2

I would like to a centre a two-column tabular environment such that the amount of whitespace between the end of the text block of the first column and the column separator is the same as the whitespace between the column separator and the beginning of the text block of the second column.

In other words, in the MWE below, the red line should arrive exactly between the two columns and not aligned with the beginning of the second column, such that the text is equally balanced around it. Both columns should, however, be left-aligned.

I have tried playing around with @{} expressions, but to no avail. I have taken a look at tabulary and tabularx. Maybe array provides a basis for a solution, but I haven't figured out what column specification would allow me to do that. Having \newline seems to further complicate the issue, but I don't they a way around them, as each row in the left column corresponds to a variable number of rows in the right column.

\documentclass{memoir}

\usepackage{tikz}

\begin{document}

\newcommand{\jury}{%
Président du jury et \newline examinateur interne &  Nom du professeur   \newline Institution                                  \\%
Examinateur externe                               &  Nom du professeur   \newline Faculté ou département \newline Institution  \\%
Examinateur interne                               &  Nom du professeur   \newline Institution                                  \\%
Directeur de recherche                            &  Jean-Claude Van Damme \newline ULB                                     \\%
Codirecteur de recherche                          &  Steve McQueen       \newline USCFA \newline
}

\thispagestyle{empty}
\newlength{\centeradjust}
\calccentering{\centeradjust}  % Calculate center length and stores in centeradjust
\begin{adjustwidth*}{\centeradjust}{-\centeradjust}   % Adjust center
\begin{adjustwidth}{-1cm}{-1cm}
  \begin{tikzpicture}[remember picture,overlay]
    \draw[red] (current page.north) -- (current page.south);
  \end{tikzpicture}
  \begin{center}
  \begin{OnehalfSpace}
    \vspace*{3\baselineskip}
     {\Large Centered page using adjustwidth (as per the \texttt{memoir} manual)}

     \vfill

     The following table is not centered the way I want it to be.\\[1cm]
    \renewcommand{\arraystretch}{2}
     \begin{tabular}{p{5cm}@{}p{5cm}@{}}
      \jury
    \end{tabular}
   \vspace*{3\baselineskip}
 \end{OnehalfSpace}
 \end{center}
\end{adjustwidth}
\end{adjustwidth*}

\end{document}

MWE with red line in the centre

  • 1
    The problem is that the p{5cm} are not being filled. You could add \centering or \raggedleft to each column using \newcolumntype. – John Kormylo Jun 23 '17 at 18:56
  • For this particular dataset, \begin{tabular}{@{\hspace{1.3cm}}p{3.75cm}@{\hspace{1cm}}p{5cm}@{}} can help, but as John points out, the issue is unused space on the right side of column 1. – Steven B. Segletes Jun 23 '17 at 19:31
3

No need to guess the widest entry:

\documentclass{memoir}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}

\usepackage{xcolor}

\newcommand{\juryitem}[2]{}
\newlength{\jurywidth}

\newcommand{\printjury}{%
  \begin{center}
  % this just prints the divider line (remove in the final version)
  \makebox[\textwidth]{%
    \smash{\vrule width 0.1pt depth \textheight height 0pt}%
  }
  %%% end part to remove
  \sbox0{%
    \def\juryitem##1##2{\begin{tabular}{@{}l@{}}##1\end{tabular}}%
    \begin{tabular}{@{}l@{}}\jury\end{tabular}%
  }%
  \setlength{\jurywidth}{\wd0}%
  \sbox0{%
    \def\juryitem##1##2{\begin{tabular}{@{}l@{}}##2\end{tabular}}%
    \begin{tabular}{@{}l@{}}\jury\end{tabular}%
  }%
  \ifdim\wd0>\jurywidth \setlength{\jurywidth}{\wd0}\fi
  \renewcommand{\arraystretch}{3}%
  \def\juryitem##1##2{%
    \renewcommand\arraystretch{1}%
    \begin{tabular}[t]{@{}l@{}}##1\end{tabular}
    &
    \renewcommand\arraystretch{1}%
    \begin{tabular}[t]{@{}l@{}}##2\end{tabular}
  }%
  \begin{tabular}{@{}p{\jurywidth}@{\hspace{2cm}}p{\jurywidth}@{}}
  \jury
  \end{tabular}%
  \end{center}
  \thispagestyle{empty}
  \clearpage
}

\begin{document}

\newcommand{\jury}{%
  \juryitem
    {Président du jury et \\ examinateur interne}
    {Nom du professeur \\ Institution}
  \\
  \juryitem
    {Examinateur externe}
    {Nom du professeur \\ Faculté ou département \\ Institution}
  \\
  \juryitem
    {Examinateur interne}
    {Nom du professeur \\ Institution}
  \\
  \juryitem
    {Directeur de recherche}
    {Jean-Claude Van Damme \\ ULB}
  \\
  \juryitem
    {Codirecteur de recherche}
    {Steve McQueen \\ USCFA}
  \\
  \juryitem
    {Codirecteur de recherche}
    {Steven Seagal \\ Texas Rangers}
}

\printjury

\end{document}

The 2cm in the definition is the space between the columns, adjust it at will.

Remember to remove the part used for printing the dividing line.

enter image description here

For obvious reasons, I had to include Steven Seagal and Chuck Norris.


The idea is to input the jury members in a way that's convenient for using it in various ways. So I use it for measuring the left column, ignoring the right one, then for measuring the right column and saving the widest length in a parameter. Then the list is typeset with the given linewidth.

  • That's very nice! I'll have to read on the ## notation though to understand how it works! Now, I'm getting errors with, I think, the use of the ampersand when i define \printjury inside of a class file. Do I have to do something special to use & in this mode? – Joey Dumont Jun 23 '17 at 21:02
  • @JoeyDumont Not that I know. – egreg Jun 23 '17 at 21:05
  • Hmm, okay. I'll dig around then! – Joey Dumont Jun 23 '17 at 21:06
3

To make sure that both columns are 100% filled, grab the longest entry and set the column-width as the length of it. This is quite easy using the \widthof command from the calc package.

\documentclass{memoir}
\usepackage{tikz}
\usepackage{calc}
\begin{document}

\newcommand{\jury}{%
Président du jury et\newline examinateur interne & Nom du professeur\newline Institution       \\%
Examinateur externe      & Nom du professeur\newline Faculté ou département\newline Institution\\%
Examinateur interne      & Nom du professeur\newline Institution                               \\%
Directeur de recherche   & Jean-Claude Van Damme\newline ULB                                   \\%
Codirecteur de recherche & Steve McQueen\newline USCFA
}

\thispagestyle{empty}
\newlength{\centeradjust}
\calccentering{\centeradjust}  % Calculate center length and stores in centeradjust
\begin{adjustwidth*}{\centeradjust}{-\centeradjust}   % Adjust center
\begin{adjustwidth}{-1cm}{-1cm}
  \begin{tikzpicture}[remember picture,overlay]
    \draw[red] (current page.north) -- (current page.south);
  \end{tikzpicture}
  \begin{center}
  \begin{OnehalfSpace}
    \vspace*{3\baselineskip}
     {\Large Centered page using adjustwidth (as per the \texttt{memoir} manual)}

     \vfill

     The following table is not centered the way I want it to be.\\[1cm]
    \renewcommand{\arraystretch}{2}
     \begin{tabular}{ p{\widthof{Codirecteur de recherche}} @{\hspace{2em}} p{\widthof{Jean-Claude Van Damme}} @{}}
      \jury
    \end{tabular}
   \vspace*{3\baselineskip}
 \end{OnehalfSpace}
 \end{center}
\end{adjustwidth}
\end{adjustwidth*}

\end{document}

enter image description here

  • 1
    Yup, that's as symmetrical as your are going to get with left aligned paragraphs. – John Kormylo Jun 23 '17 at 19:25
  • I agree. I think the writer of the thesis format guideline needs a stern talking to :) – Joey Dumont Jun 23 '17 at 19:27
  • Since I would like this code to be part of a generic class for typesetting our university's theses, using an explicit string to determine the width is not ideal, but it's good a first step, thanks! – Joey Dumont Jun 23 '17 at 19:34
2

Note that \newline adds space where \linebreak does not.

\documentclass{memoir}
\usepackage{array}
\usepackage{tikz}

\begin{document}

\newcommand{\jury}{%
Président du jury et\linebreak examinateur interne &  Nom du professeur   \newline Institution                                  \\%
Examinateur externe                                &  Nom du professeur   \newline Faculté ou département \newline Institution  \\%
Examinateur interne                                &  Nom du professeur   \newline Institution                                  \\%
Directeur de recherche                             &  Jean-Claude Van Damme \newline ULB                                     \\%
Codirecteur de recherche                           &  Steve McQueen       \newline USCFA \newline
}

\thispagestyle{empty}
\newlength{\centeradjust}
\calccentering{\centeradjust}  % Calculate center length and stores in centeradjust
\begin{adjustwidth*}{\centeradjust}{-\centeradjust}   % Adjust center
\begin{adjustwidth}{-1cm}{-1cm}
  \begin{tikzpicture}[remember picture,overlay]
    \draw[red] (current page.north) -- (current page.south);
  \end{tikzpicture}
  \begin{center}
  \begin{OnehalfSpace}
    \vspace*{3\baselineskip}
     {\Large Centered page using adjustwidth (as per the \texttt{memoir} manual)}

     \vfill

     The following table is not centered the way I want it to be.\\[1cm]
    \renewcommand{\arraystretch}{2}%
     \begin{tabular}{>{\raggedleft}p{5cm}|p{5cm}}
      \jury
    \end{tabular}% Note, without this comment or a \linebreak the center would be 1/2 space off.
   \vspace*{3\baselineskip}
 \end{OnehalfSpace}
 \end{center}
\end{adjustwidth}
\end{adjustwidth*}

\end{document}

demo

  • That is a nice solution, but I forgot to add a requirement! The first column should be left-aligned. – Joey Dumont Jun 23 '17 at 19:18
  • It also needs to be left-aligned. Hence the difficulty of the task. – Joey Dumont Jun 23 '17 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.