如何对齐表格顶部的行?

如何对齐表格顶部的行?

我有这个简单的乳胶表,我想将顶行(天、最低温度、最高温度)对齐到顶部。我该怎么做?

\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}

在此处输入图片描述

相关内容