3

This table comes from SAS output. The \newline is not working correctly. E.g. "Percent trimmed in tail" ought to be

Percent Trimmed In tail

but it is showing up as

Percent Trimmed In Tail

Here is a minimal example

\documentclass{article}
\usepackage{natbib}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage{longtable}

\usepackage{array}
\usepackage{listings}
\usepackage{multicol}
\usepackage{url}
\lstloadlanguages{SAS} \lstset{language = SAS}

\begin{document}
 \begin{longtable}{|r|r|r|r|r|r|r|r|r|}\hline
   \multicolumn{9}{|c|}{Trimmed Means}\\\hline
   Percent {\newline} Trimmed \newline in Tail &    Number \newline Trimmed \newline in Tail &    Trimmed \newline Mean &    Std Error \newline Trimmed \newline Mean &    \multicolumn{2}{|c|}{95\%~Confidence~Limits} &    DF &    t for H0: \newline Mu0=0.00 &    Pr~>~|t|\\\hline
\endhead
   10.27 &    27 &    463.8867 &    25.08152 &    414.4401 &    513.3332 &    208 &    18.49516 &    <.0001\\\hline
\end{longtable}
\end{document}
10
  • 3
    You need a cell spec with p{<width>} for \newline to work. Commented Jul 8, 2015 at 20:47
  • 1
    If you want to have an explicit line break, use \thead for example (requires makecell). Is this an auto-generated table?
    – user31729
    Commented Jul 8, 2015 at 20:47
  • Yes, the table was generated by SAS, but not quite correctly, apparently.
    – Peter Flom
    Commented Jul 8, 2015 at 20:57
  • @Peter Flom: No, not really. The math LaTeX is weird ;-) And I've got no idea what SAS is at all.
    – user31729
    Commented Jul 8, 2015 at 20:59
  • 1
    I should correct myself, \makecell is sufficient.
    – user31729
    Commented Jul 8, 2015 at 21:01

1 Answer 1

1

Now you can write multiline cells without fixing the column widths with the new LaTeX3 package tabularray:

\documentclass{article}
\usepackage[a4paper,left=2cm,right=2cm]{geometry}

\usepackage{tabularray}

\begin{document}

\begin{longtblr}[
  caption = {Long Caption},
  label = {tblr:test},
]{
  colspec={|r|r|r|r|r|r|r|r|r|}, rowhead = 2, row{2}={m},
  cell{1}{1} = {c=9}{c}, cell{2}{5} = {c=2}{c},
}
\hline
 Trimmed Means \\
\hline
 {Percent \\ Trimmed \\ in Tail} & {Number \\ Trimmed \\ in Tail} & {Trimmed \\ Mean} &
 {Std Error \\ Trimmed \\ Mean}  & {$95\%$ \\ Confidence Limits} & & DF &
 {$t$ for $H_0$: \\ $\mu_0=0.00$} & $\mathrm{Pr}>|t|$ \\
\hline
 $10.27$ & $27$ & $463.8867$ & $25.08152$ & $414.4401$ & $513.3332$ & $208$ & $18.49516$ & $<.0001$ \\
\hline
\end{longtblr}

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