2

I was working on some tables and thought about having the text for the leftmost index wrapped on two lines.

However, I wish to have the linespacing for cells with text wrapped – Connected components and Estimated sequence length – to be smaller than the overall setting for the document just to make clear we are still within the same cell. See below for an example: enter image description here

and related code

\documentclass[12pt]{report}


\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{float}

\usepackage{longtable,booktabs,siunitx}
\renewcommand{\baselinestretch}{1.5}

\begin{document}

\begin{longtable}{@{\extracolsep{\fill}} p{0.20\linewidth} *{4}{S[table-format=2.2]}}
\caption[\textbf{}]{\textbf{} } 
\label{table:graphs} \\
\toprule
& \multicolumn{4}{c}{\textbf{GRAPH}} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{\texttt{minigraph-CACTUS}}  
& \multicolumn{2}{c}{\texttt{PGGB}} \\
\cmidrule{2-3} \cmidrule{4-5}

& {\textit{GRCh38-only}} & {\textit{CHM13}} & {\textit{GRCh38-only}} & {\textit{CHM13}} \\
\cmidrule{2-5}

\centering\textbf{Node Count} &  \\
\centering\textbf{Edge Count} &  \\
\centering\textbf{Total length} &  \\
\centering\textbf{Dead ends} &  \\
\centering\textbf{Connected components} &  \\
\centering\textbf{Median depth} &  \\
\centering\textbf{Estimated sequence length} &  \\
\midrule[\heavyrulewidth]
\end{longtable}

\end{document}

Now, I tried some options but they all screwed up the between-cell spacing... is there a way to do so locally just for those two cells preserving the overall document formatting? Thanks in advance!

3
  • Something like `\centering\baselineskip=12pt\textbf{Connected components} & \` Commented Mar 30 at 18:38
  • 1
    Off-topic: \centering doesn't take an argument.
    – cfr
    Commented Mar 30 at 18:42
  • @PietervanOostrum thanks. I will go for the answer by jlab since it provides the necessary context and explanations but is also formatted accordingly.
    – Matteo
    Commented Mar 30 at 19:14

2 Answers 2

3

The cells display the required line space since you set \renewcommand{\baselinestretch}{1.5} (I hope you didn't do that only for the table, otherwise you should better use \renewcommand{\arraystretch}{1.5}).

You need to restore the \baselinestretch. A \selectfont command is needed to make if effective:

\renewcommand{\baselinestretch}{1}\selectfont

For example, define a new command:

\newcommand{\smallerbaseline}{\renewcommand{\baselinestretch}{1}\selectfont}

and use it where needed

\smallerbaseline\textbf{Connected components}

For the tabular, you can include it in its definition:

\begin{longtable}{
  @{\extracolsep{\fill}}
  >{\smallerbaseline} p{0.20\linewidth}
  *{4}{S[table-format=2.2]}
}

Full example (I also moved the \centering and bod face setting of the first column into the tabular definition).

\documentclass[12pt]{report}


\usepackage[letterpaper,margin=1in]{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{float}

\usepackage{longtable,booktabs,siunitx}
\renewcommand{\baselinestretch}{1.5}

\newcommand{\smallerbaseline}{\renewcommand{\baselinestretch}{1}\selectfont}

\begin{document}

\begin{longtable}{%
    @{\extracolsep{\fill}}
    >{\centering\arraybackslash\smallerbaseline\bfseries} p{0.20\linewidth}
    *{4}{S[table-format=2.2]}
}
\caption[\textbf{}]{\textbf{} }
\label{table:graphs} \\
\toprule
& \multicolumn{4}{c}{\textbf{GRAPH}} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{\texttt{minigraph-CACTUS}}
& \multicolumn{2}{c}{\texttt{PGGB}} \\
\cmidrule{2-3} \cmidrule{4-5}

& {\textit{GRCh38-only}} & {\textit{CHM13}} & {\textit{GRCh38-only}} & {\textit{CHM13}} \\
\cmidrule{2-5}
Node Count &  \\
Edge Count &  \\
Total length &  \\
Dead ends &  \\
Connected components &  \\
Median depth &  \\
Estimated sequence length &  \\
\midrule[\heavyrulewidth]
\end{longtable}

\end{document}

change baseline in the first column

An alternative, with \arraystretch (add \smallerbaseline after \begingroup if you really need a larger baseline in your document):

\begingroup
\renewcommand{\arraystretch}{1.5}
\begin{longtable}{%
    @{\extracolsep{\fill}}
    >{\centering\arraybackslash\bfseries} p{0.20\linewidth}
    *{4}{S[table-format=2.2]}
}
\caption[\textbf{}]{\textbf{} }
\label{table:graphs} \\
\toprule
& \multicolumn{4}{c}{\textbf{GRAPH}} \\
\cmidrule{2-5}
& \multicolumn{2}{c}{\texttt{minigraph-CACTUS}}
& \multicolumn{2}{c}{\texttt{PGGB}} \\
\cmidrule{2-3} \cmidrule{4-5}

& {\textit{GRCh38-only}} & {\textit{CHM13}} & {\textit{GRCh38-only}} & {\textit{CHM13}} \\
\cmidrule{2-5}
Node Count &  \\
Edge Count &  \\
Total length &  \\
Dead ends &  \\
Connected components &  \\
Median depth &  \\
Estimated sequence length &  \\
\midrule[\heavyrulewidth]
\end{longtable}
\endgroup
1
  • much appreciated. Thanks for the insights on the whole process as well as alternatives. It works perfectly! I had to set a global \renewcommand{\baselinestretch}{1.5} as this is the requirement for my PhD thesis, but definitely it isn't something I would have mess with locally otherwise.
    – Matteo
    Commented Mar 30 at 19:18
2

If you are going to change \baselinestretch, it is probably better to use setspace so you have ready-made means to alter it and some of the side-effects are mitigated for you. However, you should know that the standard classes can misbehave when the value is altered globally because lots of things depend on the value of \baselinestretch in ways which may not be obvious. setspace improves things a bit, but only a bit.

I'd actually use a modified version of the singlespace environment in the tabular cells to avoid excessive spacing between the rows. In the code below, I call this environment singlespaced and apply it to the first column (together with \centering and \bfseries) using the > and < facilities of the array package, which you are already implicitly loading.

\documentclass[12pt,letterpaper]{report}
\usepackage[margin=1in]{geometry}
% \usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{subcaption}
% \usepackage{caption}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{float}

\usepackage{longtable,booktabs,siunitx}
\usepackage{setspace}
\makeatletter
\newenvironment{singlespaced}{%
  \vskip \baselineskip
  \setstretch {\setspace@singlespace}%
  \vskip -2\baselineskip
}{%
  \par
}
\makeatother
\setstretch{1.5}

\begin{document}

  \begin{longtable}{@{\extracolsep{\fill}} >{\bfseries\centering\singlespaced} p{0.20\linewidth} <{\endsinglespaced} *{4}{S[table-format=2.2]}}
  \caption[\textbf{}]{\textbf{} } 
  \label{table:graphs} \\
  \toprule
  & \multicolumn{4}{c}{\textbf{GRAPH}} \\
  \cmidrule{2-5}
  & \multicolumn{2}{c}{\texttt{minigraph-CACTUS}}  
  & \multicolumn{2}{c}{\texttt{PGGB}} \\
  \cmidrule{2-3} \cmidrule{4-5}
  
  & {\textit{GRCh38-only}} & {\textit{CHM13}} & {\textit{GRCh38-only}} & {\textit{CHM13}} \\
  \cmidrule{2-5}
  
  Node Count &  \\
  Edge Count &  \\
  Total length &  \\
  Dead ends &  \\
  Connected components &  \\
  Median depth &  \\
  Estimated sequence length &  \\
  \bottomrule
\end{longtable}

\end{document}

[No image due to Okular/KDE bug which renders them so ugly you would scream in horror if not omitted.]

7
  • What does @{\extracolsep{\fill}} do?
    – cfr
    Commented Mar 30 at 19:13
  • also a very good alternative to what jlab proposed. For fairness, I had to accept his answer since it came first but I appreciate the effort and the additional suggestions, as I'm quite new to LaTex and trying to learn as much as possible! From what I understood in another post (tex.stackexchange.com/questions/714115/…) where I was asking basic ideas for tables layout, @{\extracolsep{\fill}} should fill spaces between columns to get the table matching textwidth. I hope I got it right.
    – Matteo
    Commented Mar 30 at 19:26
  • @Matteo I have no objection to your accepting jlab's answer if it best meets your needs, but you shouldn't accept answers on a first-to-answer basis. That's not what acceptance is supposed to indicate. But, again, I'm not urging you to accept mine. This is just a general not about how the site is supposed to work.
    – cfr
    Commented Mar 30 at 19:57
  • @Matteo But you are not using it in between columns in this case, but before the first column which is not the same thing. If it did work, it would shift your table's columns right, with all the extra space to the left of the first column. If you add showframe when loading geometry, you'll see that's not the case. In fact, the table is centred. longtable does that automatically.
    – cfr
    Commented Mar 30 at 20:00
  • mmm so I think that is a particular trick Mico used in that scenario. After a quick googling I found this: tex.stackexchange.com/questions/532890/…. I hope it helps.
    – Matteo
    Commented Mar 31 at 11:28

You must log in to answer this question.

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