需要制作这个表,我应该使用其他程序吗?

需要制作这个表,我应该使用其他程序吗?

教授希望我们重现这个表格来学习如何使用 LaTeX,但我所学到的只是 LaTeX 表格是一场噩梦。我已经为此苦恼了好几个星期。我们上了一堂关于表格环境的课,并被告知要谷歌搜索 hhline 和 multirow 之类的东西。一直在尝试严格遵循所有软件包的文档。使用一些外部工具并将表格作为图像输入会更好吗?这在 LaTeX 中很常见吗?下面是我需要的表格、我最近对它的编码尝试以及它的外观。 所需的表

\documentclass{article}

\usepackage{array}
\usepackage{tabularx}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{dcolumn}
\usepackage{hhline}

\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
% Y is left justified column of shifting width
\newcolumntype{Z}{>{\centering\arraybackslash}X}
% Z is center justified column of shifting width
\newcolumntype{W}{>{\raggedleft\arraybackslash}X}
% W is right justified column of shifting width
\newcolumntype{U}{D{+}{\pm}{-1}}
% U is a column with the '+' in each row aligned and turned into \pm
\newcolumntype{.}{D{.}{.}{-1}}
% . is a column aligned on '.'

\begin{document}

\section{Tables in \LaTeX  are Evil}

\begin{table}

\caption{Table 1: This is the table caption, it is placed above the Table itself. The caption should
describe the table fully so that the reader does not need to refer to the text to understand
the table. This table uses many of the alignment and text placement options.}

\begin{tabularx}{600pt}{||Z|Z|Z||Y|W||}

\hhline{|t:===::==:t|}
  Column 1 & Column 2 & Column 3 & Column 4 & Column 5 \\
  (cm)     & (pc)     & ($m^3$)    &          &          \\
\hhline{||-|-|--|-||}
  \multicolumn{1}{||U|}{\multirow{2}{*}{12.3 + 0.3\\98.8 + 0.4}}    & 
  \multicolumn{1}{|U|}{\multirow{2}{*}{154.2 + 0.8\\245.3 + 0.9}}  & 
  \multicolumn{1}{|.||}{\multirow{2}{*}{11.2\\31.8}}                & 
  \multirow{2}{*}{67.8\\134.2}                                   & 
  \multirow{2}{*}{13\\27}                                        \\
% Must leave an empty row to prevent conflicts with the multirows, i think
  \\
\hhline{||-|-|-||~|~||}
  \multicolumn{3}{||Z||}{this text spans 3 columns} & & \\
\hhline{||-|-|--|-||}
  \multirow{4}{=}{this text spans \\4 rows and is \\centered \\vertically}    &
  \multirow{4}{=}{like this}                                                  &
  \multirow{4}{=}{you \\can tweak the \\line breaks \\using stuff}            &
                                                                              &
  \multicolumn{1}{|Z||}{\multirow{4}{=}{and center\\text\\horizontally\\as well}}  \\
 %so those were all 4x multirows, then a linebreak, so i need to leave a gap and a linebreak 3 times?
 \\
 %so the content was row1, the prev comment was row2, this is row3?
 \\
 %gosh i hope this works, latex SUCKS
 \\
\hhline{||=:=:=#=:=||}
  \multicolumn{3}{||Z||}{\multirow{4}{=}{You can even combine the multicolumn \\ and multirow commands}} &  &  \\
  %doing this again i guess
  \\
  %its stupid i have to manually count a bunch of linebreaks to make sure is works
  \\
  %this would be easier in mspaint
  \\
\hhline{|b:=:=:=#=:=:b|}

\end{tabularx}

\end{table}

\end{document}

我有的那张桌子很糟糕。

答案1

  • \multirow如果没有必要就不要使用……这里你也不必使用。此表中没有单个实际的多行单元格。

    我们可以使用紧密的将多行内容放入单元格中tabular,这里我使用了\miniTab

  • 我已经将第一个替换::为。\hhlinet

  • tabularx如果您不想让桌子伸展到一定长度,请不要使用。tabular您只需要正常长度。

  • 不要实际使用

    1. 双线,
    2. 垂直线或
    3. 垂直双线

    在现实世界。

    查看booktabs包裹和问答

  • siunitx包裹(→) 可以帮助排版表格中的数字和不确定的数字(但我相信,如果没有一些手动工作,这两者都做不到)。

代码

\documentclass{article}
\usepackage{multicol}
\usepackage{hhline}

\newcommand*{\ttMacro}[1]{\texttt{\textbackslash#1}}
\newcommand*{\miniTab}[3][c]{\begin{tabular}[#1]{@{}#2@{}}#3\end{tabular}}
\newcommand*{\unc}[2]{\( #1 \pm #2 \)}
\begin{document}

\section{Tables in \LaTeX\ are evil}
\begin{table}
\caption{
  This is the table caption, it is placed above the Table itself.
  The caption should describe the table fully
  so that the reader does not need to refer to the text to understand the table.
  This table uses many of the alignment and text placement options.}
\centering
\begin{tabular}{||c|c|c||l|r||}
  \hhline{|t:===t==:t|}
  Column 1 & Column 2 & Column 3 & Column 4 & Column 5 \\
   (cm)    &   (pc)   & ($m^3$)  &          &          \\
  \hhline{||-|-|--|-||}
  \miniTab{c}{\unc{12.3}{0.3} \\ \unc{98.8}{0.4}}
           & \miniTab{c}{\unc{154.2}{0.8}\\\unc{245.3}{0.9}}
                      & \miniTab{c}{11.2\\31.8}
                                 & \miniTab{l}{67.8\\134.2}
                                            & \miniTab{r}{13\\27} \\
  \hhline{||-|-|-||~|~||}
  \multicolumn{3}{||c||}{this text spans 3 columns} & & \\
  \hhline{||-|-|--|-||}
  \miniTab{l}{this text spans \\4 rows and is \\centered \\vertically}
           & like this
                      & \miniTab{l}{you \\
                                    can tweak the \\
                                    line breaks \\
                                    using \ttMacro{\textbackslash}}
                                & & \miniTab{c}{and center \\
                                                text \\
                                                horizontally \\
                                                as well} \\
  \hhline{||=:=:=#=:=||}
  \multicolumn{3}{||c||}{\miniTab{c}{\\
    You can even combine the \ttMacro{multicolumn} \\
    and the \ttMacro{multirow} commands \\ ~}} & & \\
  \hhline{|b:=:=:=b=:=:b|}
\end{tabular}
\end{table}
\end{document}

输出

在此处输入图片描述

答案2

替代:

\documentclass{article}
\usepackage{multicol}
\usepackage{hhline}
\usepackage{tabularx}
\usepackage{ragged2e}

\newcommand*{\ttMacro}[1]{\texttt{\textbackslash#1}}
\newcolumntype{C}{>{\Centering}X}
\renewcommand\tabularxcolumn[1]{m{#1}}
\begin{document}
\noindent
\begin{tabularx}{\linewidth}{||C|C|C||>{\RaggedRight}X|>{\RaggedLeft}X||}\hhline{|t:===t==:t|}
  Column 1 & Column 2 & Column 3 & Column 4 & Column 5\\
   (cm)    &   (pc)   & ($m^3$)  &          &          \\\hhline{||-|-|--|-||}
  $12.3\pm 0.3$\newline$98.8\pm0.4$ &  $154.2\pm0.8$ \newline$245.3\pm0.9$ &  
    11.2\newline31.8 & 67.8\newline134.2 & 13\newline27 \\ \hhline{||-|-|-||~|~||}
  \multicolumn{3}{||c||}{this text spans 3 columns} & & \\\hhline{||-|-|--|-||}
  \RaggedRight this text spans 4 rows and is centered vertically  & like this
    & you can tweak the line breaks using \ttMacro{newline}
    & & \Centering and center text horizontally as well \\\hhline{||=:=:=#=:=||}
  \multicolumn{3}{||p{6cm}||}{You can even combine the \ttMacro{multicolumn}
            and the \ttMacro{multirow} commands} & & \\\hhline{|b:=:=:=b=:=:b|}
\end{tabularx}

\end{document}

在此处输入图片描述

相关内容