![如何对齐表格顶部的行?](https://linux22.com/image/477721/%E5%A6%82%E4%BD%95%E5%AF%B9%E9%BD%90%E8%A1%A8%E6%A0%BC%E9%A1%B6%E9%83%A8%E7%9A%84%E8%A1%8C%EF%BC%9F.png)
我有这个简单的乳胶表,我想将顶行(天、最低温度、最高温度)对齐到顶部。我该怎么做?
\begin{tabular}{ | l | l | l | p{8cm} |}
\hline
Day & Min Temp & Max Temp &
\begin{minipage}{\textwidth}
\begin{itemize}
\setlength{\itemindent}{-.2in}
\setlength\itemsep{-0.5em}
\item El 1
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\end{itemize}
\end{minipage}
\\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
\end{tabular}
答案1
只是改变
\begin{minipage}{\textwidth}
到
\begin{minipage}[t]{\textwidth}
即添加[t]
定位说明符。
完整的 MWE(最小工作示例),对您的代码进行一些额外的调整,以使表格材料从纯粹的美学角度来看更具吸引力。
\documentclass{article}
\usepackage{array}
\setlength\extrarowheight{2pt}
\begin{document}
\begin{tabular}{ | l | l | l | >{\raggedright\arraybackslash}p{8cm} |}
\hline
Day & Min Temp & Max Temp &
\begin{minipage}[t]{\hsize}
\begin{itemize}
\setlength{\itemindent}{-.2in}
\setlength\itemsep{-0.5em}
\item El 1
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2\strut
\end{itemize}
\end{minipage} \\
\hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\
\hline
\end{tabular}
\end{document}
答案2
使用该enumitem
包,您可以定义自己的itemize
表格环境。在第二个示例中,我已将tabularx
表格宽度设置为与文本宽度相同:
\documentclass{article}
\usepackage{enumitem}
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,nosep,after=\strut,align=parleft,leftmargin=*,after=\vspace{-\baselineskip},before=\vspace{-0.75\baselineskip}}
\usepackage{tabularx}
\begin{document}
\begin{tabular}{ | l | l | l | p{8cm} |}
\hline
Day & Min Temp & Max Temp &
\begin{tabitemize}
\item El 1
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\end{tabitemize}
\\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
\end{tabular}
\bigskip
\begin{tabularx}{\textwidth}{ | l | l | l | X |}
\hline
Day & Min Temp & Max Temp &
\begin{tabitemize}
\item El 1
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\end{tabitemize}
\\ \hline
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \hline
\end{tabularx}
\end{document}
为了使表格看起来更加开放,您还可以使用以下booktabs
包:
\documentclass{article}
\usepackage{enumitem}
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,nosep,after=\strut,align=parleft,leftmargin=*,after=\vspace{-\baselineskip},before=\vspace{-0.75\baselineskip}}
\usepackage{tabularx}
\usepackage{booktabs}
\begin{document}
\begin{tabularx}{\textwidth}{ l l l X }
\toprule
Day & Min Temp & Max Temp &
\begin{tabitemize}
\item El 1
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\item El 2
\end{tabitemize}
\\ \midrule
Monday & 11C & 22C & A clear day with lots of sunshine.
However, the strong breeze will bring down the temperatures. \\ \bottomrule
\end{tabularx}
\end{document}