在表中使用多个多行命令时出现问题

问题描述 投票:0回答:1

我正在尝试使用格式like this.创建一个三列表。当然,描述比名称列长。另外,出于美学原因,我想在示例列中使用\ multicolumn命令。这是代码,

\begin{document}
\begin{table}
    \begin{tabular}{|c|p {5 cm}|p {5 cm}|}
        \hline
        \multirow{2}{*}{Complex Type} & \multirow{2}{5 cm}{\parbox[c]{5 cm}{This variable type is used to declare a complex number, the real part and also the imaginary part.}} & \multicolumn{1}{l|}{Defining a complex number 3.0 + 5.0 i :} \\
             & & \multicolumn{1}{l|}{complex :: a = (3.0, 5.0)} \\
        \hline 
        \multirow{4}{*}{Character Type} & \multirow{4}{4 cm}{This variable type is used to store one character by default. It can be used to store string or multiple characters using the len modifier. The len modifier works exactly the same as kind modifier. The example is on how to declare two variables, var1 for a character and var 2 for a sentence holder.} & character :: var1 \\
             & & character (len = 40) :: var2 \\
             & & var1 = "A" \\
             & & var2 = "How do you turn this on?" \\
        \hline
    \end{tabular}
\end{tabular}

如果代码太长,我道歉。似乎问题是因为没有针对最高单元调整整个行单元的高度。它基于第一列而不是固定。我试过尝试几种方法,没有任何作用。有什么建议?

latex pdflatex
1个回答
1
投票

看起来你正在尝试使用\multicolumn\multirow这些复杂的结构来改变对齐并添加换行符,这可以更容易地完成:

\documentclass{article}

\usepackage{geometry}
\usepackage{multirow}
\usepackage{array}

\begin{document}
\begin{table}
    \begin{tabular}{|c|m{5cm}|>{\raggedright\arraybackslash}m{6.2cm}|}
        \hline
        Complex Type &
        This variable type is used to declare a complex number, the real part and also the imaginary part. & 
        Defining a complex number 3.0 + 5.0 i : \linebreak
        complex :: a = (3.0, 5.0) \\
        \hline 
        Character Type & 
        This variable type is used to store one character by default. It can be used to store string or multiple characters using the len modifier. The len modifier works exactly the same as kind modifier. The example is on how to declare two variables, var1 for a character and var 2 for a sentence holder. & 
        character :: var1 \linebreak
        character (len = 40) :: var2 \linebreak
        var1 = "A" \linebreak
        var2 = "How do you turn this on?" \\
        \hline
    \end{tabular}
\end{table}

\end{document}

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.