换行的文本与列值合并

换行的文本与列值合并

我正在使用以下代码来制作表格,但看起来一点也不美观。我能够换行,但它会合并到列中给出的值中。任何帮助都将不胜感激。

\begin{document}
\begin{table}[]
\begin{tabular}{ccccc}
\hline
\multirow{2}{*}{\textbf{Years}} & \multicolumn{3}{c}{\textbf{Days}}                                                                                         
& \multirow{2}{*}{\parbox{4cm} {\centering \textbf{Sediment volume excavated 
in the year represented by the boundary of the corresponding range of 
years}}} \\ \cline{2-4}
                                     & \textbf{\parbox{1.5cm} 
{\centeringQ\textgreater{}10 (m\textsuperscript{3}/s)}} & 
\textbf{\parbox{1.5cm} {\centering10\textgreater{}Q\textgreater{}20 
(m\textsuperscript{3}/s)}} & \textbf{\parbox{1.5cm} {\centering 
Q\textgreater{}20 (m\textsuperscript{3}/s)}} &                         \\ 
\hline
2002-2003                                & 18                                
& 15                                                & 3                                 
& 486                                               \\ 
2003-2006                                & 25                                
& 18                                                & 7                                 
& 666                                               \\ 
2006-2010                                & 24                                
& 22                                                & 2                                 
& 217                                                \\ 
2010-2013                                & 29                                
& 19                                                & 10                                
& 126                                                \\ \hline
\end{tabular}
\end{table}

\end{document}

在此处输入图片描述

在此处输入图片描述

答案1

为大段文字使用标题。

\documentclass{article}
\usepackage{booktabs,siunitx,caption}

\sisetup{per-mode=symbol}

\begin{document}

\begin{table}[htp]
\centering

\caption{Sediment volume excavated in the year represented by
  the boundary of the corresponding range of years}

\begin{tabular}{ccccc}
\toprule
Years & \multicolumn{3}{c}{Days (\si{\meter\cubed\per\second})} & Sediment \\
\cmidrule(lr){2-4}
& $Q<10$ & $10<Q<20$ & $Q>20$ \\
\midrule
2002-2003 & 18 & 15 &  3 & 486 \\
2003-2006 & 25 & 18 &  7 & 666 \\
2006-2010 & 24 & 22 &  2 & 217 \\
2010-2013 & 29 & 19 & 10 & 126 \\
\bottomrule
\end{tabular}

\end{table}

在此处输入图片描述

答案2

\multirow故意与下一行(或几行)重叠。您需要一个支柱将第三行向下推,这意味着它必须放在第二行上。

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\sbox0{\parbox[t]{4cm}{\centering \textbf{Sediment volume excavated 
in the year represented by the boundary of the corresponding range of 
years}}}% measuer height
\begin{tabular}{ccccc}
\hline
\multirow{2}{*}{\textbf{Years}} & \multicolumn{3}{c}{\textbf{Days}}                                                                                         
& \multirow{2}{*}{\usebox0} \\
\cline{2-4}
& \textbf{\parbox[t]{1.5cm} 
{\centering Q\textgreater{}10 (m\textsuperscript{3}/s)}} & 
\textbf{\parbox[t]{1.5cm} {\centering 10\textgreater{}Q\textgreater{}20 
(m\textsuperscript{3}/s)}} & \textbf{\parbox[t]{1.5cm} {\centering 
Q\textgreater{}20 (m\textsuperscript{3}/s)}} & 
\rule[\dimexpr \arraystretch\normalbaselineskip-\dp0]{0pt}{0pt} \\ 
\hline
2002-2003                                & 18                                
& 15                                                & 3                                 
& 486                                               \\ 
2003-2006                                & 25                                
& 18                                                & 7                                 
& 666                                               \\ 
2006-2010                                & 24                                
& 22                                                & 2                                 
& 217                                                \\ 
2010-2013                                & 29                                
& 19                                                & 10                                
& 126                                                \\ \hline
\end{tabular}
\end{table}

\end{document}

演示


此版本将第一行向下移动。请注意,\raisebox这次我使用了。 \multirow始终尝试将条目居中,这绝对是我们不希望看到的。要覆盖第二行,我需要将深度设置为 0pt,这可以使用可选参数来完成。

记住这些调整的基线在哪里非常重要,尤其是在使用时\parbox

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\sbox0{\parbox[b]{4cm}{\centering \strut\textbf{Sediment volume excavated 
in the year represented by the boundary of the corresponding range of 
years}}}% measure height
\sbox1{\textbf{\parbox[t]{1.5cm} 
{\centering Q\textgreater{}10 (m\textsuperscript{3}/s)}}}%
\begin{tabular}{ccccc}
\hline
\multirow{2}{*}{\textbf{Years}} & \multicolumn{3}{c}{\textbf{Days}}                                                                                         
& \raisebox{\dimexpr -\dp0-\ht1-\dp1}%
    [\dimexpr \ht0-\dp0-\ht1-\dp1][0pt]{\usebox0} \\
\cline{2-4}
& \usebox1 & 
\textbf{\parbox[t]{1.5cm} {\centering 10\textgreater{}Q\textgreater{}20 
(m\textsuperscript{3}/s)}} & \textbf{\parbox[t]{1.5cm} {\centering 
Q\textgreater{}20 (m\textsuperscript{3}/s)}} & \\ 
\hline
2002-2003                                & 18                                
& 15                                                & 3                                 
& 486                                               \\ 
2003-2006                                & 25                                
& 18                                                & 7                                 
& 666                                               \\ 
2006-2010                                & 24                                
& 22                                                & 2                                 
& 217                                                \\ 
2010-2013                                & 29                                
& 19                                                & 10                                
& 126                                                \\ \hline
\end{tabular}
\end{table}

\end{document}

第二个演示


这次,我在表格中放置了另一个表格,并将其放在\makebox一行中以匹配列宽。

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\sbox0{\begin{tabular}{@{}p{1.5cm}p{1.5cm}p{1.5cm}@{}}
  \multicolumn{3}{c}{\textbf{Days}} \\
  \hline
  \centering\textbf{Q\textgreater{}10 (m\textsuperscript{3}/s)} &
  \centering\textbf{10\textgreater{}Q\textgreater{}20 (m\textsuperscript{3}/s)} &
  \centering\textbf{Q\textgreater{}20 (m\textsuperscript{3}/s)}
\end{tabular}}% savebox not really needed here
\begin{tabular}{ccccc}
\hline
\textbf{Years} & \multicolumn{3}{c}{\usebox0} & 
\parbox{4cm}{\centering \strut\textbf{Sediment volume excavated 
in the year represented by the boundary of the corresponding range of 
years}\strut} \\
\hline
2002-2003 & \makebox[1.5cm]{18} & \makebox[1.5cm]{15} & \makebox[1.5cm]{3} & 486 \\ 
2003-2006                                & 25                                
& 18                                                & 7                                 
& 666                                               \\ 
2006-2010                                & 24                                
& 22                                                & 2                                 
& 217                                                \\ 
2010-2013                                & 29                                
& 19                                                & 10                                
& 126                                                \\ \hline
\end{tabular}
\end{table}

\end{document}

演示 3

相关内容