表格环境中的垂直间距

表格环境中的垂直间距

https://en.wikibooks.org/wiki/LaTeX/Tables#Text_wrapping_in_tables

在上面的链接中,他们给出了表格环境的描述,我需要一些类似的东西。但是,我希望第一列和第二列垂直居中。我试过array使用包,m{...}但这似乎不起作用。有人能帮我吗?谢谢!

例如,

\documentclass{article}

\usepackage[english]{babel}
\usepackage{array}

\begin{document}

\begin{center}
    \begin{tabular}{ | m{2cm} | l | l | p{5cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.  
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells 
    across most of Scotland and Northern Ireland, 
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning. 
    Conditions will improve by early afternoon and continue 
    throughout the evening. \\
    \hline
    \end{tabular}
\end{center}

\end{document}

结果几乎与 wikibooks 上的图像相同,没有任何垂直居中。

答案1

我已经尝试过数组包并使用m{...},但这似乎不起作用。

更改p{5cm}m{5cm},即更改

\begin{tabular}{ | l | l | l | p{5cm} |}

\begin{tabular}{ | l | l | l | m{5cm} |}

应该可以实现您所寻找的。

enter image description here

\documentclass{article} 
\usepackage{array} % for 'm' column type
\begin{document}
With width specified:
\begin{center}
    \begin{tabular}{ | l | l | l | m{5cm} |}
    \hline
    Day & Min Temp & Max Temp & Summary \\ \hline
    Monday & 11C & 22C & A clear day with lots of sunshine.  
    However, the strong breeze will bring down the temperatures. \\ \hline
    Tuesday & 9C & 19C & Cloudy with rain, across many northern regions. Clear spells 
    across most of Scotland and Northern Ireland, 
    but rain reaching the far northwest. \\ \hline
    Wednesday & 10C & 21C & Rain will still linger for the morning. 
    Conditions will improve by early afternoon and continue 
    throughout the evening. \\
    \hline
    \end{tabular}
\end{center}
\end{document}

答案2

您还可以使用它booktabs来改善表格的外观:

\documentclass{article}

\usepackage[english]{babel}
\usepackage{array}
\renewcommand*{\arraystretch}{1.2}
\usepackage{booktabs}
\usepackage{textcomp}
\usepackage{makecell}
\usepackage{siunitx}

\begin{document}

    \begin{center}
        \begin{tabular}{m{1.8cm}*2{S[table-format=2.0]}m{5cm}}
            \toprule
            Day & {\makecell[c]{Min Temp\\(\textdegree C)}} & {\makecell[c]{Max Temp\\(\textdegree C)}} & Summary \\ 
            \midrule
            Monday & 11 & 22 & A clear day with lots of sunshine.\newline  
            However, the strong breeze will bring down the temperatures. \\ \midrule
            Tuesday & 9 & 19 & Cloudy with rain, across many northern regions.\newline Clear spells 
            across most of Scotland and Northern Ireland, 
            but rain reaching the far northwest. \\ 
            \midrule
            Wednesday & 10 & 21 & Rain will still linger for the morning.\newline 
            Conditions will improve by early afternoon and continue 
            throughout the evening. \\
            \bottomrule
        \end{tabular}
    \end{center}

\end{document}

enter image description here

相关内容