1

I am so close to having this aligned properly, but the right-most cell is flush against the top rule whereas the left-most and center cells have a small amount of vertical space. I am trying to make the alignment uniform (either remove vertical space, or have it consistent across the row).

I've used \parbox{} to allow the multiline expression to be contained within, and horizontally aligned within, the table.

\begin{table}[h]
\caption{Title of Table.}
\begin{tabularx}{\linewidth}{p{1.4cm} p{6.9cm} p{6.8cm}} 
\toprule
Head1 & Head2 & Head3 \\
\midrule
text   & text text text text &  \parbox{6.8cm}{$BZ, CY, CX, BZ, BX, AY, AZ, \\ CY, CZ, \ldots$ } \\
\bottomrule
\end{tabularx}
\end{table}

Also, in case this is important, I have the following in my preamble for APA-formatted tables.

\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[table]{textfont=it,format=plain,justification=justified,
  singlelinecheck=false,labelsep=spaced,skip=0pt}
\captionsetup[figure]{labelsep=period,labelfont=it,justification=justified,
  singlelinecheck=false,font=doublespacing}
  • in case you feel the answer has been helpful feel free to accept the same by clicking the tick mark on the left side – js bibra Sep 21 '20 at 23:40
  • Hi @jsbibra. Sorry, I should have tagged you in my previous comment. I should have included more text in the middle column, as the amount I need (pasted into your example) makes it run wider than the page. I tried using p{width} instead of l, c, h, but this seems to produce the undesired vertical space. – Guest1729 Sep 22 '20 at 01:06
  • I just did it the "hard way," without using mathematical expressions. – Guest1729 Sep 23 '20 at 20:13
  • ...care to share this "hard way" with others? – Werner Sep 23 '20 at 20:18

4 Answers4

2

It's not very clear what you want to achieve, you should provide a complete minimal example.

Anyway, with tabularray:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs} 
\usepackage{caption}
\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[table]{textfont=it,format=plain,justification=justified,
    singlelinecheck=false,labelsep=spaced,skip=0pt}
\captionsetup[figure]{labelsep=period,labelfont=it,justification=justified,
    singlelinecheck=false,font=doublespacing}

\begin{document} \begin{table}[h] \caption{Title of Table.} \begin{tblr}{colspec={Q[1.4cm]Q[6.9cm]X[mode=math]}} \toprule Head1 & Head2 & Head3 \ \midrule text & text text text text & {BZ, CY, CX, \ BZ, BX, AY,\ AZ, CY, CZ, \ldots} \ \bottomrule \end{tblr} \end{table} \end{document}

enter image description here

CarLaTeX
  • 62,716
1

Note that a tabularx environment requires the use of an X-column in order to work properly. Without one, you might as well just use a regular tabular. Secondly, and what you're looking to change, a list of inline math elements are not breakable around ,. You'll have to change how that is managed by using content from (say) “Allowing line break at ',' in inline math mode” breaks citations:

\documentclass{article}

\usepackage{tabularx,booktabs}

% https://tex.stackexchange.com/a/19100/5764 \mathchardef\breakingcomma\mathcode\, {\catcode,=\active \gdef,{\breakingcomma\discretionary{}{}{}} } \newcommand{\mathlist}[1]{\mathcode`,=\string"8000 #1}

\begin{document}

\begin{table} \caption{Table caption} \begin{tabularx}{\linewidth}{ p{14mm} p{69mm} X } \toprule Head1 & Head2 & Head3 \ \midrule text & text text text text & $\mathlist{BZ, CY, CX, BZ, BX, AY, AZ, CY, CZ, \ldots}$ \ \bottomrule \end{tabularx} \end{table}

\end{document}

Werner
  • 603,163
0

https://tex.stackexchange.com/a/467445/197451

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage{booktabs}
\usepackage{multirow}

\newcolumntype{C}{>{\centering\arraybackslash}X} \renewcommand\tabularxcolumn[1]{m{#1}}

\begin{document} \begin{table}[h] \caption{Title of Table.} \setlength{\extrarowheight}{2pt} \begin{tabularx}{\linewidth}{ccC} \toprule Head1 & Head2 & Head3 \ \midrule text & text text text text &{{\parbox{3cm}{$BZ, CY, CX, BZ, BX,\ AY, AZ, CY, CZ, \ldots$ }}} \ \bottomrule \end{tabularx} \end{table} \begin{table}[h] \caption{Title of Table.} \begin{tabularx}{\textwidth}{ccC} \toprule Head1 & Head2 & Head3 \ \midrule text & text text text text & {{$BZ, CY, CX, BZ, BX, AY, AZ, CY, CZ, \ldots$ }} \ \bottomrule \end{tabularx} \end{table} \end{document}

js bibra
  • 21,280
  • Thanks for your reply. I should have included more text in the middle column, as the amount I need (pasted into your example) makes it run wider than the page. I tried using p{width} instead of l, c, h, but this seems to produce the undesired vertical space. – Guest1729 Sep 21 '20 at 18:19
0

The baseline of a \parbox with multiple lines of text in it is the baseline of its bottommost row, giving the whole box excessive height above the baseline. Such a box is not aligned at the baseline but at the top, making it appear flush against the rule above.

The solution is to include a "strut" in its first line of text so that the (imaginary) baseline of its topmost row aligns with the baselines in the other columns. Plain TeX offers the macros \strut and \mathstrut for this.

text & \strut text text text text &
$\mathlist{\mathstrut BZ, CY, CX, BZ, BX, AY, AZ, CY, CZ, \ldots}$ \\

See also Identical spacing of inference lines with Bussproofs.