4

I am writing a table in latex in which one entry (an algorithm name) is too large. I divided its content in three lines as it is shown in the following table:

\begin{tabular}{lccc}
    \toprule
    \textbf{Problem} & \multicolumn{3}{c}{\textbf{Mean objective value}} \\
    \midrule
    & Algorithm X & \scriptsize  Algorithm X without &  Algorithm X with \\
    &             & \scriptsize component A and with &  component C \\
    &             & \scriptsize and component B      & \\
    \midrule
    eil51         & \textbf{427.267} & \underline{1286.37} & 439.467 \\
    \bottomrule
\end{tabular}

However, those lines are too separated when compiling to pdf.

enter image description here

Is it possible to reduce the space between two table lines? Is there any other solution?

Possible solutions:

  • I have tried \renewcommand{\baselinestretch}{2} and it did not work.
5
  • 2
    Welcome to TeX.SX! Please post working examples, not just fragments. \\[-0.3ex] for example will reduce the space, but only if really needed. Since you're using booktabs: \addlinespace[-0.3ex]
    – user31729
    Sep 20, 2015 at 10:33
  • Thank you very much! The command \addlinespace[-1.5ex] worked perfectly.
    – andreshp
    Sep 21, 2015 at 11:04
  • Ok, and that's why you accepted the other answer which does not use \addlinespace? :D
    – user31729
    Sep 21, 2015 at 11:12
  • I would accept both, but I used his command in other tables too! ^^
    – andreshp
    Sep 21, 2015 at 11:21
  • Alright, noticed for future
    – user31729
    Sep 21, 2015 at 11:22

2 Answers 2

6

I'd add the clauses below the main entry in the header:

\documentclass{article}

\usepackage{booktabs}

\newcommand{\descrcell}[2]{%
  \scriptsize
  \begin{tabular}[t]{@{}c@{}}\normalsize#1\\#2\end{tabular}%
}


\begin{document}
\begin{tabular}{lccc}
\toprule
\textbf{Problem} & \multicolumn{3}{c}{\textbf{Mean objective value}} \\
\midrule
& Algorithm X
& \descrcell{Algorithm X}{without component A \\ and with component B}
& \descrcell{Algorithm X}{with component C} \\
\midrule
eil51         & \textbf{427.267} & \underline{1286.37} & 439.467 \\
\bottomrule
\end{tabular}

\end{document}

enter image description here

5
  • Very clever and elegant solution. Thank you very much!
    – andreshp
    Sep 21, 2015 at 11:18
  • Can we apply this solution for the title section for the Mean objective value? When I wrap it inside \descrcell{} it adds additonal space
    – alper
    Dec 27, 2022 at 13:48
  • @alper Very cryptic. What do you want to do with the header?
    – egreg
    Dec 27, 2022 at 13:52
  • Example one column of my header: i.stack.imgur.com/dqQAr.png ; I just wanted to remove spacing in it. But since the journal template provides this, its better I don't change its format.
    – alper
    Dec 27, 2022 at 13:56
  • @alper You're looking at the wrong tool. Please ask a question with the details.
    – egreg
    Dec 27, 2022 at 13:58
6

It's possible to reduce or enlarge the linespacing with \addlinespace if the booktabs package is used:

\documentclass{article}

\usepackage{booktabs}
\begin{document}
Without \verb!\addlinespace!

\begin{tabular}{lccc}
    \toprule
    \textbf{Problem} & \multicolumn{3}{c}{\textbf{Mean objective value}} \\
    \midrule
    & Algorithm X & \scriptsize  Algorithm X without &  Algorithm X with \\
    &             & \scriptsize component A and with &  component C \\
    &             & \scriptsize and component B      & \\
    \midrule
    eil51         & \textbf{427.267} & \underline{1286.37} & 439.467 \\
    \bottomrule
\end{tabular}

With \verb!\addlinespace!

\begin{tabular}{l*{3}c}    
    \toprule
    \textbf{Problem} & \multicolumn{3}{c}{\textbf{Mean objective value}} \\
    \midrule
    & Algorithm X & \scriptsize  Algorithm X without &  Algorithm X with \\
    \addlinespace[-0.3ex]
    &             & \scriptsize component A and with &  component C \\
    \addlinespace[-0.4ex]
    &             & \scriptsize and component B      & \\
    \midrule
    eil51         & \textbf{427.267} & \underline{1286.37} & 439.467 \\
    \bottomrule


\end{tabular}

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