表格的多列中出现意外缩进

表格的多列中出现意外缩进

当我在表格中使用多列时,与未定义多列的其他行相比,文本总是缩进。

我该如何解决这个问题?

\documentclass{article}

\usepackage{multicol}                           % define a multicols environment which typesets text in multiple columns
\usepackage{colortbl}                           % background color for row, columns or individual cells in a table
\usepackage{xcolor}                             % foreground (text, rules, etc.) and background colour management

\definecolor{beige}{cmyk}{0.16,0.03,0.31,0}
\definecolor{shamrock}{cmyk}{0.71,0.29,1,0.13}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}    % define a new column type for a fixed-width right-aligned column - middle vertical alignment
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}   % define a new column type for a fixed-width left-aligned column - middle vertical alignment

\begin{document}

\begin{tabular}{L{110mm} R{35mm}} 
    \cellcolor{beige}
    \textbf{Column title} 
    & \cellcolor{beige}
    \textbf{99.999,99 EUR} \\
    \multicolumn{2}{L{145mm}}{
        \color{shamrock}I don't understand why this text is left indented. The other text
        is not indented in the table. I don't understand why this text is left indented. The other text
        is not indented in the table.
    } \\
    \color{shamrock}Title: 
    & \color{shamrock}99.999,99 EUR \\
\end{tabular}

\end{document}

答案1

m类型没有考虑两列之间的列间距,因此您指定的\multicolumn宽度比表格的实际宽度短。由于我不太清楚的原因,\multicolumn然后对齐文本,使右边缘与第二列的末尾齐平。请注意,pb要这样做。如果您\multicolumn进一步减小宽度,效果非常明显。(尝试将宽度减小到 100 毫米,以了解我的意思。)

解决这个问题的最简单方法是消除两个普通列之间的列间距:

\documentclass{article}
\usepackage{array}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\begin{document}
\begin{tabular}{L{110mm}@{}R{35mm}} 
  \textbf{Column title}  & \textbf{99.999,99 EUR} \\
  \multicolumn{2}{L{145mm}}{
      CI don't understand why this text is left indented. The other text 
        is not indented in the table. I don't understand why this text is left indented. The other text
        is not indented in the table.
    } \\
  Title: & 99.999,99 EUR \\
\end{tabular}
\end{document}

结果:

在此处输入图片描述

答案2

的大小\multicolumn没有考虑到\tabcolsep列之间的两个。

在下面的例子中我使用了m,因此中心多列单元格是合理的。

请注意,multicol与此示例无关;不要先加载colortbl然后xcolor,最好只使用table选项加载后者。

\documentclass{article}

\usepackage[table]{xcolor}

\definecolor{beige}{cmyk}{0.16,0.03,0.31,0}
\definecolor{shamrock}{cmyk}{0.71,0.29,1,0.13}

\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}

\begin{document}

\begin{tabular}{L{110mm} R{35mm}} 
\cellcolor{beige}\textbf{Column title} & \cellcolor{beige}\textbf{99.999,99 EUR} \\
\multicolumn{2}{m{\dimexpr145mm+2\tabcolsep}}{%
  \color{shamrock}I don't understand why this text is left indented. The other text
  is not indented in the table. I don't understand why this text is left indented.
  The other text is not indented in the table.
} \\
\color{shamrock}Title: & \color{shamrock}99.999,99 EUR \\
\end{tabular}

\end{document}

在此处输入图片描述

相关内容