1

Consider the following MWE:

\documentclass[letterpaper]{article}
\usepackage[letterpaper,top=2.5cm,bottom=2.5cm,lmargin=2.5cm,rmargin=2.5cm]{geometry}
\usepackage{array,booktabs,tabularx}
\usepackage{ragged2e}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabularx}{\textwidth}{*{3}{L}}
\hline
\textbf{Sample Test Sample} & \textbf{Sample Test Sample} & \textbf{Sample Test Sample Sample Test Sample}%
\\\hline%
    \begin{itemize}%
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \end{itemize}%
    &
    \begin{itemize}%
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample 
    \end{itemize}%
    &   
    \begin{itemize}%
    \item Sample Test Sample
    \item Sample Test Sample
    \end{itemize}%  
    \\\hline
\end{tabularx}
\end{center}
\end{document}

enter image description here

How can I vertically center the first row only using tabularx and if possible remove the extra vertical space as shown in the diagram?

2
  • Off-topic: The option list top=2.5cm,bottom=2.5cm,lmargin=2.5cm,rmargin=2.5cm may be expressed more succinctly as margin=2.5cm.
    – Mico
    Commented Jul 10, 2023 at 5:18
  • 1
    @Mico thanks for that hint!
    – azetina
    Commented Jul 10, 2023 at 5:19

2 Answers 2

1

How can I vertically center the first row only using tabularx ... [emphasis added]

I suggest you use a \multicolumn{1} "wrapper" for the third cell in the header row. Further details are provided in the code posted below.

How can I ... remove the extra vertical space [that is] shown in the diagram?

I suggest you employ the enumitem package and use its \newlist and \setlist macros to define an itemize-like environment that suppresses the excess whitespace automatically. In the code below, this environment is called tabitemize. By defining such a bespoke environment, the properties of the basic itemize environment are left untouched.


enter image description here

\documentclass{article}
\usepackage[letterpaper,margin=2.5cm]{geometry}

\usepackage{booktabs,tabularx,ragged2e}
\newcolumntype{L}{>{\RaggedRight}X}
\newcolumntype{M}[1]{>{\RaggedRight}m{#1}} % use 'm' column type

\usepackage{enumitem} % for '\newlist' and '\setlist' macros
% use '\newlist' and '\setlist' to define a new itemize-like env.:
\newlist{tabitemize}{itemize}{1}
\setlist[tabitemize]{label=\textbullet,left=0pt,noitemsep,
           before={\begin{minipage}[t]{\hsize}},
           after ={\end{minipage}}}
\newlength\mylen
\setlength\mylen{\dimexpr0.333\textwidth-1.333\tabcolsep\relax}

\begin{document}

\begin{center}
\renewcommand{\arraystretch}{1.25}
\begin{tabularx}{\textwidth}{@{} LLL @{}} % no whitespace padding at the edges
\toprule
\textbf{Sample Test Sample} & \textbf{Sample Test Sample} & 
\multicolumn{1}{M{\mylen}}{\textbf{Sample Test Sample Sample Test Sample}}\\ 
\midrule
    \begin{tabitemize}
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
    \end{tabitemize}
    &
    \begin{tabitemize}
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample 
    \end{tabitemize}
    &   
    \begin{tabitemize}
    \item Sample Test Sample
    \item Sample Test Sample
    \end{tabitemize} 
\\
\bottomrule
\end{tabularx}
\end{center}

\end{document}
1
  • 1
    I got an underfull message but I fixed with \RaggedRight in the minipage. Thanks a lot!
    – azetina
    Commented Jul 10, 2023 at 5:33
1

If you willing to use tabullarray package instead of tabularx, the MWE is a bit simpler and shorter but compilation time is longer:

\documentclass[letterpaper]{article}
\usepackage[margin=2.5cm]{geometry}
\usepackage{lipsum}

\usepackage{microtype}
\usepackage{ragged2e}
\usepackage{tabularray}
    \UseTblrLibrary{booktabs, varwidth}
\usepackage{enumitem}

\begin{document}
    \begin{center}
    \setlist[itemize]{nosep, leftmargin=*}
\begin{tblr}{colspec = {@{} *{3}{X[cmd=\RaggedRight\hspace{0pt}]} @{}},
             row{1}  = {font=\bfseries, m},
             stretch=-1,%<--- remove extra space above and below lists
                        % with nosep option; see doc p.51 tabularray
              measure = vbox,
              row{3-Z} = {rowsep=5pt}
             }
    \toprule
Sample Test Sample
    & Sample Test Sample
        &   Sample Test Sample Sample Test Sample   \\
    \midrule
    \begin{itemize}
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
\item Sample Test Sample
    \end{itemize}
    &   \begin{itemize}
    \item Sample Test Sample
    \item Sample Test Sample
    \item Sample Test Sample
        \end{itemize}
        &   \begin{itemize}
        \item Sample Test Sample
        \item Sample Test Sample
                \end{itemize}                           \\
    \begin{itemize}
\item   \lipsum[1][1-2]
\item  \lipsum[1][3-5]
    \end{itemize}
    &   \begin{itemize}
    \item   \lipsum[1][1-2]
    \item  \lipsum[1][3-5]
        \end{itemize}
        &   \begin{itemize}
        \item   \lipsum[1][1-2]
        \item  \lipsum[1][3-5]
                \end{itemize}                           \\
    \bottomrule
\end{tblr}
    \end{center}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .