1

I have a table like the following, and would like to have the contents of the columns vertically top aligned. Additionally the first column should be centered horizontally and the second column should be like it is now (left aligned, due to p{width}. How is it possible to achieve this? I know about the array package parameters m,b,p but I don't know how to center them and also top align them at the same time.

enter image description here

\documentclass[11pt]{report}
\usepackage{longtable}
\usepackage{array}
\usepackage{lipsum}

\begin{document}
\begin{longtable}{ p{0.25\textwidth} | p{0.75\textwidth} }
\caption{A simple longtable example}\\
%\label{somelabelofatableusinglongtable}
\hline
\textbf{First entry} & \textbf{Second entry} \\
\hline
\endfirsthead
\multicolumn{2}{c}%
{\tablename\ \thetable\ -- \textit{Continued from previous page}} \\
\hline
\textbf{\textit{page}} & \textbf{\textit{Content}} \\\hline \endhead
\hline
\endhead
\hline \multicolumn{2}{r}{\textit{Continued on next page}} \\
\endfoot
\hline
\endlastfoot

       i & \lipsum[1].\\
    & \\
       \textcolor{blue}{i} & \textcolor{blue}{All grammar has been checked.} \\
       & \\
    \hline

    N/A & \lipsum[1]   \\
    \end{longtable}
\end{document}
2
  • For the first column, you use wc{0.25\textwidth} in the place of p{0.25\textwidth}. The p column top-aligns its contents.
    – Bernard
    Sep 5 at 22:26
  • as Bernard said or use >{\centering} p{0.25\textwidth} if the first column needs line breaking as well as centering Sep 6 at 0:10
2

With tabularray is easy:

\documentclass[11pt]{report}
\usepackage{xcolor}
\usepackage{tabularray}
\usepackage{lipsum}

\begin{document}
\begin{longtblr}[
    caption={A simple longtable example},
    label={somelabelofatableusinglongtable}
                ]{hlines,
                  colspec={ l | X[j] },
                  rowhead = 1,
                  cell{1}{1,2} = {c=1}{c}, % center content each 1st row, 
                  row{1}={font=\bfseries},
                }
First entry     &   Second entry                    \\
i               &   \lipsum[1]                      \\
\SetRow{fg=blue}
i               &   All grammar has been checked.   \\*
  N/A           & \lipsum[1]                        \\
\SetRow{fg=blue}
ii              &   All grammar has been checked.   \\*
  N/A           & \lipsum[1]                        \\
    \end{longtblr}
\end{document}

Note: from today, September 7th, the version 2021N of the tabularray package can be downloaded by in MiKTeX Console. Compiling with it gives the following result:

enter image description here

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.