1

I'm trying to use a tabular* environment to create a simple table with two centered columns that are spaced apart so that the table fills the entire page.

\documentclass{article}
\begin{document}

  \fbox{

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill} } | c | c | }
    \hline
    \Large{Supervisor} & \Large{Student} \\
    \hline
    \Large{prof. X Y Z} & \Large{A B C} \\
    \hline
    \end{tabular*}

  }

\end{document}

It ends up looking like this:

enter image description here

Note that not only does the table not space the cells apart properly, the top and left lines of the table do not come to a nice corner.

(I don't strongly care about borders not meeting since this table will ultimately not show them, but I drew them here to help debug.)

A similar table on another person's machine looks ok, so maybe there is something I'm missing on my system?

  • note size commands do not take an argumnet, \Large{Supervisor} should be \Large Supervisor (although that does not change the output here) – David Carlisle Feb 26 at 21:47
  • \estracolsep does not affect the gap to the left of the first column, nor the gap to the right of the last column. You will need to compute the width instead. – John Kormylo Feb 26 at 21:48
  • @JohnKormylo I've also tried {c @{\extracolsep{\fill}} c} exactly as recommended here: tex.stackexchange.com/a/56552/145783 with approximately the same result. \hfill didn't seem to do anything. – rgov Feb 26 at 21:50
4

You are adding a lot of extra space

enter image description here

\documentclass{article}
\begin{document}

\setlength\fboxsep{0pt}

\noindent
\hspace*{-\fboxrule}%SPACE
  \fbox{%SPACE
%SPACE
    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}%SPACE
} | c | c | }
    \hline
    \Large Supervisor & \Large Student  \\
    \hline
    \Large prof. X Y Z & \Large A B C \\
    \hline
    \end{tabular*}%SPACE
%SPACE
  }%SPACE
\hspace*{-\fboxrule}%SPACE

\end{document}
|improve this answer|||||
  • The whitespace around the table is expected by the university that issued the template. For your code I still get imgur.com/oWyH30Y — better corners, but the cells aren't spaced quite right. – rgov Feb 26 at 21:54
  • @rgov from the exact code I post above? that looks very wrong, can you add the full log that you get from this file (add it to my answer as a code block) or to your question – David Carlisle Feb 26 at 21:55
  • @rgov no the whitespace was wrong. you had a paragraph indent, two \fboxrule rules from the \fbox two \fboxsep spaces form the \fbox but you forced the inner tabular to be \textwidth wide so the entire construct is overfull by \parindent+2\fboxrule+2\fboxsep so you need to set those spaces to 0 or use a value less than \textwidth in the tabular* but the other space tokens that I highlight are causing your rules not to line up at the corners. – David Carlisle Feb 26 at 21:58
  • I added it, @David-carlisle. – rgov Feb 26 at 21:58
  • @rgov thanks (it got rejected by the automatic site checker for some reason but I see it in the history) – David Carlisle Feb 26 at 22:02
3

Is this what you were looking for?

\documentclass{article}
\begin{document}

\bgroup
\Large 
\setlength{\tabcolsep}{0pt}%
\sbox0{\begin{tabular}{|c|c|}% measure width
Supervisor & Student \\
prof. X Y Z & A B C \\
\end{tabular}}%
\setlength{\tabcolsep}{\dimexpr \textwidth-\wd0}%
\divide\tabcolsep by 4
\noindent\begin{tabular}{|c|c|}
    \hline
    Supervisor & Student \\
    \hline
    prof. X Y Z & A B C \\
    \hline
    \end{tabular}
\egroup

\end{document}

demo


This is a somewhat simpler approach which divides the tabular into two equal columns.

\documentclass{article}
\newlength{\tempdima}
\begin{document}

\bgroup
\Large 
\setlength{\tempdima}{\dimexpr 0.5\textwidth-2\tabcolsep-1.5\arrayrulewidth}%
\noindent\begin{tabular}{|c|c|}
    \hline
    \makebox[\tempdima][c]{Supervisor} & \makebox[\tempdima][c]{Student} \\
    \hline
    prof. X Y Z & A B C \\
    \hline
    \end{tabular}
\egroup

\end{document}
|improve this answer|||||
  • The OP was using a broken format # 2019-10-01 Release which was replaced by # 2019-10-01 Patch level 1 a few days later.... – David Carlisle Feb 26 at 22:17
  • but +1 this is what the OP should do, I concentrated on what was technically wrong in the OPs code in my answer rather than give a better approach:-) – David Carlisle Feb 26 at 22:27
2

Since you obviously don't want the rules at the end, I make three proposals. Using a macro is a good way to postpone the decision at the end without changing the document proper.

\documentclass{article}
\usepackage{showframe} % in order to see the page margins

\newcommand{\supervisorstudentA}[2]{%
  \par\noindent
  \begin{tabular}[t]{@{}c@{}} Supervisor \\ prof.\ #1 \end{tabular}\hfill
  \begin{tabular}[t]{@{}c@{}} Student \\ #2 \end{tabular}\par
}
\newcommand{\supervisorstudentB}[2]{%
  \par\noindent
  \hspace*{4em}
  \begin{tabular}[t]{@{}c@{}} Supervisor \\ prof.\ X Y Z \end{tabular}\hfill
  \begin{tabular}[t]{@{}c@{}} Student \\ A B C \end{tabular}%
  \hspace*{4em}\par
}
\newcommand{\supervisorstudentC}[2]{%
  \par\noindent
  \hspace*{\stretch{0.25}}%
  \makebox[0pt]{\begin{tabular}[t]{@{}c@{}} Supervisor \\ prof.\ X Y Z \end{tabular}}%
  \hspace*{\stretch{0.5}}%
  \makebox[0pt]{\begin{tabular}[t]{@{}c@{}} Student \\ A B C \end{tabular}}%
  \hspace*{\stretch{0.25}}\par
}

\begin{document}

\supervisorstudentA{X Y Z}{A B C}

\bigskip

\supervisorstudentB{X Y Z}{A B C}

\bigskip

\supervisorstudentC{X Y Z}{A B C}

\end{document}

In the third one the two parts are exactly midway in either half of the text width.

enter image description here

|improve this answer|||||

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.