2

I have this simple latex table, I want to align top rows(Day, Min Temp, Max Temp) top. How Can I do it ?

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

Thank in advanced !! enter image description here

1
  • please, next time provide complete small document beginning wit \documentclass{...} and ending with \end{document} containing your table. now people who like to help you should guessing about your document preamble ...
    – Zarko
    Mar 31, 2019 at 9:53

2 Answers 2

3

Just change

\begin{minipage}{\textwidth}

to

\begin{minipage}[t]{\textwidth}

i.e., add the [t] positioning specifier.


A full MWE (minimum working example), with some additional tweaks to your code to make the tabular material more appealing from a purely aesthetic point of view.

enter image description here

\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

With the enumitem package you can define your own itemize environment for tables. In the second example I have used tabularx to make the table as wide as the textwidth:

enter image description here

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

For a more open look of the table, you could also use the booktabs package:

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

enter image description here

3
  • The baselines of "El 1" and of the other header items don't seem to matched up perfectly in either of the screenshots. Can you think of a way to fix this?
    – Mico
    Mar 31, 2019 at 9:52
  • @Mico: Thanks for pointing this out. I did not notice that. Aparently, changing from before=\vspace{-0.75\baselineskip} to before=\vspace{-0.7\baselineskip} should improve the alignment.
    – leandriis
    Mar 31, 2019 at 9:59
  • Another approach would consist of adding \newenvironment{mylist}{\begin{minipage}[t]{\hsize}\begin{tabitemize}}{\end{tabitemize}\end{minipage}} in the preamble and using \begin{mylist} and \end{mylist} in the body of the document. This would obviate the need to specify any kind of before=... adjustments.
    – Mico
    Mar 31, 2019 at 10:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.