1

I am trying to have the inner text of each square of my \tabular fill the whole space available. For example, in the tabular below, I would like my a2 and b2 occupy the entire column under s2 in a way to not reveal clear empty spaces where would be c2 and d2.

\usepackage{amssymb}
\usepackage{multirow}

...

\begin{center}\begin{tabular}{|c|c|c|c|}
  \hline
  \multicolumn{4}{|c|}{\bf title}\\
  \hline \hline
  \bf s1 & \bf s2 & \bf s3 & \bf s4\\
  \hline \hline
  \multirow{4}{*}{$\varnothing$} & a2 & a3 & a4\\
  & b2 & b3 & b4\\
  & & c3 & c4\\
  & & d3 &\\
  \hline
\end{tabular}\label{table}\end{center}

Would anyone have a clue, please?


Edit:

\usepackage{amssymb}
\usepackage{multirow}

...

\begin{center}\begin{tabular}{|c|c|c|c|}
  \hline
  \multicolumn{4}{|c|}{\bf Requête}\\
  \hline \hline
  \bf s1 & \bf s2 & \bf s3 & \bf s4\\
  \hline \hline
  \multirow{5}{*}{$\varnothing$} & \multirow{2}{*}{a2} & a3 & \multirow{3}{*}{a4}\\
  & \multirow{2}{*}{b2} & b3 & \multirow{3}{*}{b4}\\
  & & c3 & \multirow{3}{*}{c4}\\
  & & d3 &\\
  & & e3 &\\
  \hline
\end{tabular}\end{center}

After Ignasi post, I popularized to the entire table. But a malfunction appears under 's2': Table

1
  • I've updated the answer for five rows.
    – Ignasi
    Apr 28, 2015 at 7:47

2 Answers 2

2

You can use \multirow and some spacing hacks to get this result (see first table below), but without knowing more about your data it's hard to see how this would help the reader.

It might be clearer to rotate your table, as in the second example below, which also uses the booktabs package for (arguably) more attractive table formatting.


Note that \bf is a deprecated command; use \textbf{} instead. Even better, as I show here, is to define a semantic command like \tableheader to separate style from content. There are table packages that will make that even easier.

I would also suggest using a table caption instead of a title row, and using etoolbox to center all the tables.


\documentclass{article}
\usepackage{multirow} % for \multirow
\usepackage{amssymb} % for \varnothing
\usepackage[position=above]{caption} % for table caption positioned above

\usepackage{booktabs} % for more attractive table spacing and rules
\usepackage{etoolbox} % center the tables
\AtEndEnvironment{table}{\centering}

\newcommand{\tableheader}[1]{\textbf{#1}}

\begin{document}
\begin{table}
\caption{Title}
\label{table}
\begin{tabular}{|c|c|c|c|}
\hline
%\multicolumn{4}{|c|}{\tableheader{title}}\\ % use caption instead?
%\hline \hline
\tableheader{s1} & \tableheader{s2} & \tableheader{s3} & \tableheader{s4}\\
\hline \hline
\multirow{4}{*}{$\varnothing$} & 
    \multirow{4}{*}{%
        \vspace*{\fill}
        \renewcommand{\arraystretch}{2}
        \begin{tabular}{@{}c}
        a2\\
        b2\\
        \end{tabular}%
        \vspace*{\fill}%
    } & a3 & a4\\
 & & b3 & b4\\
 & & c3 & c4\\
 & & d3 &\\
\hline
\end{tabular}
\end{table}

%***************************************
\begin{table}
\caption{Rotated}
\label{table:rotated}
\begin{tabular}{*{5}c}
\toprule
S-value & \multicolumn{4}{c}{Result}\\
\midrule
s1      & $\varnothing$ & $\varnothing$ & $\varnothing$ & $\varnothing$\\
s2      & a2 & b2 & &\\
s3      & a3 & b3 & c3 & d3\\
s4      & a4 & b4 & c4 & d4\\
\bottomrule
\end{tabular}
\end{table}

\end{document}

In the future please post a full example including all packages used (in this case multirow and amssymb).

enter image description here enter image description here

2
  • Thank you. I edited my post to show an unexpected feature that seems to appear in your code too: my s2 column is not well spread.
    – wipman
    Apr 28, 2015 at 6:49
  • I found the answer. I just moved my s2 multicolumn content one row down, and the texts are correctly placed.
    – wipman
    Apr 28, 2015 at 7:03
2

Not sure to understand the question, but something like this?

\documentclass{article}
\usepackage{multirow}
\usepackage{amsmath,amssymb}

\begin{document}
\begin{center}\begin{tabular}{|c|c|c|c|}
  \hline
  \multicolumn{4}{|c|}{\bf title}\\
  \hline \hline
  \bf s1 & \bf s2 & \bf s3 & \bf s4\\
  \hline \hline
  \multirow{4}{*}{$\varnothing$} & \multirow{2}{*}{a2} & a3 & a4\\
  & & b3 & b4\\
  & \multirow{2}{*}{b2} & c3 & c4\\
  & & d3 &\\
  \hline
\end{tabular}\label{table}\end{center}
\end{document}

enter image description here

Proposed solution needs to be adjusted with any new row which is added to the original table. In case it's extended to five rows, multirow could be only applied to fourth column while second column is composed for misplaced regular cells.

\documentclass{article}
\usepackage{multirow}
\usepackage{amsmath,amssymb}

\begin{document}
\begin{center}\begin{tabular}{|c|c|c|c|}
  \hline
  \multicolumn{4}{|c|}{\bf title}\\
  \hline \hline
  \bf s1 & \bf s2 & \bf s3 & \bf s4\\
  \hline \hline
  \multirow{5}{*}{$\varnothing$} &  & a3 & \multirow{2}{*}{a4}\\
  & a2 & b3 & \\
  & & c3 & b4\\
  & b2 & d3 &\multirow{2}{*}{c4}\\
  & & e3 &\\
  \hline
\end{tabular}\label{table}\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 .