0

I am trying to create a table but the first vertical line is not in the correct place- all of the horizontal lines of the table just out slightly to the left of the vertical line. How can I fix this? (Note: I am using a template, so while I think a big chunk of the preamble has no effect on this table I decided to leave it in in case there is a glitch I don't know about.)

I am using the tabular* environment described in this article: https://en.wikibooks.org/wiki/LaTeX/Tables. I don't have this alignment problem when I use the normal tabular environment but I want to adjust the width of my columns which I do not believe is an option in the tabular environment.

Thank you in advance for your help!

\documentclass[11pt, a4paper]{article}
\usepackage[inner=2.5cm,outer=2.5cm,top=2.5cm,bottom=2.5cm]{geometry}
\pagestyle{empty}
\usepackage{graphicx}
\usepackage{fancyhdr, lastpage, bbding, pmboxdraw}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\pagestyle{fancyplain}
\fancyhf{}
\lhead{ \fancyplain{}{Title} }
\rhead{ \fancyplain{}{Date} }
\thispagestyle{plain}

\usepackage{listings}
\usepackage{caption}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{acronym}
\usepackage{amsthm}
\usepackage{multicol}
\VerbatimFootnotes

\lstset{
basicstyle=\ttfamily,
keywordstyle=\color{OliveGreen}, 
commentstyle=\color{gray},
numbers=left,   
numberstyle=\tiny, 
stepnumber=1, 
numbersep=5pt,           
backgroundcolor=\color{lightlightgray},
frame=none,    
tabsize=2,
captionpos=t,   
breaklines=true,  
breakatwhitespace=false,  
showspaces=false,   
showtabs=false,       
columns=flexible,              
morekeywords={__global__, __device__}, 
}

\begin{document}
\begin{center}
{\Large{Syllabus}}
\end{center}
\begin{center}
Fall 2018
\end{center}

\begin{table}[h]
    \begin{tabular*}{0.85\textwidth}{ @{\extracolsep{\fill} } |c|c|c|}
        \hline
         & Monday & Wednesday\\
        \hline
        Week 1 & August 27 & August 29\\
        \hline
        Week 2 & September 3 & September 5\\
        \hline
        Week 3 & September 10 & September 12\\
        \hline
        Week 4 & September 17 & September 19\\
        \hline
        Week 5 & September 24 & September 26\\
        \hline
        Week 6 & October 1 & October 3\\
        \hline
        Week 7 & October 8 & Octobere 10\\
        \hline
        Week 8 & October 15 & October 17\\
        \hline
        Week 9 & October 22 & October 24\\
        \hline
        Week 10 & October 29 & October 31\\
        \hline
        Week 11 & November 5 & November 7\\
        \hline
        Week 12 & November 12 & November 14\\
        \hline
        Week 13 & November 19 & November 21\\
        \hline
        Week 14 & November 26 & November 28\\
        \hline
        Week 15 & December 4 & December 6\\
        \hline
        Week 16 & December 10 & December 12\\
        \hline
    \end{tabular*}
\end{table}

\end{document}
  • 2
    instead of \begin{tabular*}{0.85\textwidth}{@{\extracolsep{\fill} } c|c|c|} you should write \begin{tabular*}{0.85\textwidth}{| @{\extracolsep{\fill} } c|c|c|} (see position of the |) – Zarko Aug 25 '18 at 21:09
  • @Zarko whoops, this should have been obvious! Thank you! – MathStudent1324 Aug 26 '18 at 1:41
3

You can make your table with tabularx, and there's no problem. I also added some improvements and simplification to the code:

\documentclass[11pt, a4paper]{article}
\usepackage[margin=2.5cm]{geometry}
\pagestyle{empty}
\usepackage{graphicx}
\usepackage{fancyhdr, lastpage, bbding, pmboxdraw}
\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\pagestyle{fancyplain}
\fancyhf{}
\lhead{ \fancyplain{}{Title} }
\rhead{ \fancyplain{}{Date} }
\thispagestyle{plain}

\usepackage{listings}
\usepackage{caption, tabularx}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{acronym}
\usepackage{amsthm}
\usepackage{multicol}
\VerbatimFootnotes

\lstset{
basicstyle=\ttfamily,
keywordstyle=\color{OliveGreen},
commentstyle=\color{gray},
numbers=left,
numberstyle=\tiny,
stepnumber=1,
numbersep=5pt,
backgroundcolor=\color{lightlightgray},
frame=none,
tabsize=2,
captionpos=t,
breaklines=true,
breakatwhitespace=false,
showspaces=false,
showtabs=false,
columns=flexible,
morekeywords={__global__, __device__},
}

\begin{document}

\begin{center}
{\Large{Syllabus}} \\[5ex]
Fall 2018
\end{center}

\begin{table}[h]
\setlength{\extrarowheight}{2pt}
\centering
    \begin{tabularx}{0.85\textwidth}{|c|*{2}{>{\centering\arraybackslash}X|}}
        \hline
         & Monday & Wednesday\\
        \hline
        Week 1 & August 27 & August 29\\
        \hline
        Week 2 & September 3 & September 5\\
        \hline
        Week 3 & September 10 & September 12\\
        \hline
        Week 4 & September 17 & September 19\\
        \hline
        Week 5 & September 24 & September 26\\
        \hline
        Week 6 & October 1 & October 3\\
        \hline
        Week 7 & October 8 & Octobere 10\\
        \hline
        Week 8 & October 15 & October 17\\
        \hline
        Week 9 & October 22 & October 24\\
        \hline
        Week 10 & October 29 & October 31\\
        \hline
        Week 11 & November 5 & November 7\\
        \hline
        Week 12 & November 12 & November 14\\
        \hline
        Week 13 & November 19 & November 21\\
        \hline
        Week 14 & November 26 & November 28\\
        \hline
        Week 15 & December 4 & December 6\\
        \hline
        Week 16 & December 10 & December 12\\
        \hline
    \end{tabularx}

\end{table}

\end{document} 

enter image description here

3

You discovered that tabular* doesn't really like vertical rules in tables (and neither do I).

\documentclass[11pt,a4paper]{article}
\usepackage[
  inner=2.5cm,
  outer=2.5cm,
  top=2.5cm,
  bottom=2.5cm,
  headheight=13.6pt, % <--- don't forget
]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr, lastpage, bbding, pmboxdraw, tabularx}

\usepackage{listings}
\usepackage{caption}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{acronym}
\usepackage{amsthm}
\usepackage{multicol}
\VerbatimFootnotes

\newcolumntype{Y}{>{\centering\arraybackslash}X}

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\fancypagestyle{plain}
\fancyhf{}
\fancyhead[L]{Title}
\fancyhead[R]{Date}

\lstset{
  basicstyle=\ttfamily,
  keywordstyle=\color{OliveGreen},
  commentstyle=\color{gray},
  numbers=left,
  numberstyle=\tiny,
  stepnumber=1,
  numbersep=5pt,
  backgroundcolor=\color{lightlightgray},
  frame=none,
  tabsize=2,
  captionpos=t,
  breaklines=true,
  breakatwhitespace=false,
  showspaces=false,
  showtabs=false,  
  columns=flexible,
  morekeywords={__global__,__device__},
}

\begin{document}

\begin{center}
{\Large{Syllabus}\\}
Fall 2018
\end{center}

\begin{center}
\begin{tabularx}{0.85\textwidth}{|c|Y|Y|}
\hline
        & Monday       & Wednesday\\
\hline
Week  1 & August 27    & August 29\\
\hline
Week  2 & September 3  & September 5\\
\hline
Week  3 & September 10 & September 12\\
\hline
Week  4 & September 17 & September 19\\
\hline
Week  5 & September 24 & September 26\\
\hline
Week  6 & October 1    & October 3\\
\hline
Week  7 & October 8    & Octobere 10\\
\hline
Week  8 & October 15   & October 17\\
\hline
Week  9 & October 22   & October 24\\
\hline
Week 10 & October 29   & October 31\\
\hline
Week 11 & November 5   & November 7\\
\hline
Week 12 & November 12  & November 14\\
\hline
Week 13 & November 19  & November 21\\
\hline
Week 14 & November 26  & November 28\\
\hline
Week 15 & December 4   & December 6\\
\hline
Week 16 & December 10  & December 12\\
\hline
\end{tabularx}
\end{center}

\end{document}

Note the setting of headheight and the adjustments to the fancyhdr code. Also, note that a table need not go in a table environment: you want that table there, with no caption.

enter image description here

A different realization with booktabs. You can judge.

\documentclass[11pt,a4paper]{article}
\usepackage[
  inner=2.5cm,
  outer=2.5cm,
  top=2.5cm,
  bottom=2.5cm,
  headheight=13.6pt, % <--- don't forget
]{geometry}
\usepackage{graphicx}
\usepackage{fancyhdr, lastpage, bbding, pmboxdraw, booktabs}

\usepackage{listings}
\usepackage{caption}
\usepackage{verbatim}
\usepackage{fancyvrb}
\usepackage{acronym}
\usepackage{amsthm}
\usepackage{multicol}
\VerbatimFootnotes

\renewcommand{\thefootnote}{\fnsymbol{footnote}}

\fancypagestyle{plain}
\fancyhf{}
\fancyhead[L]{Title}
\fancyhead[R]{Date}

\lstset{
  basicstyle=\ttfamily,
  keywordstyle=\color{OliveGreen},
  commentstyle=\color{gray},
  numbers=left,
  numberstyle=\tiny,
  stepnumber=1,
  numbersep=5pt,
  backgroundcolor=\color{lightlightgray},
  frame=none,
  tabsize=2,
  captionpos=t,
  breaklines=true,
  breakatwhitespace=false,
  showspaces=false,
  showtabs=false,  
  columns=flexible,
  morekeywords={__global__,__device__},
}

\begin{document}

\begin{center}
{\Large{Syllabus}\\}
Fall 2018
\end{center}

\begin{center}
\begin{tabular}{lll}
\toprule
& \multicolumn{1}{c}{Monday}
& \multicolumn{1}{c}{Wednesday}\\
\midrule
Week  1 & August 27    & August 29\\
Week  2 & September 3  & September 5\\
Week  3 & September 10 & September 12\\
Week  4 & September 17 & September 19\\
Week  5 & September 24 & September 26\\
Week  6 & October 1    & October 3\\
Week  7 & October 8    & Octobere 10\\
Week  8 & October 15   & October 17\\
Week  9 & October 22   & October 24\\
Week 10 & October 29   & October 31\\
Week 11 & November 5   & November 7\\
Week 12 & November 12  & November 14\\
Week 13 & November 19  & November 21\\
Week 14 & November 26  & November 28\\
Week 15 & December 4   & December 6\\
Week 16 & December 10  & December 12\\
\bottomrule
\end{tabular}
\end{center}

\end{document}

enter image description here

  • ,@egreg Off-topic question: May I ask how you render CM fonts as heavy and black as I see them in your answers here? Many a times, I refrain from using CM fonts in my lectures and notes to students because the fonts seem too light in print, especially at large sizes. I know there is pdfrender but it creates other problems and destroys the beauty of the original font. Any hints are very much appreciated, thank you. – AboAmmar Aug 26 '18 at 0:42
  • Thank you for this response! I chose the tabularx response because it seemed like an easier fix for this question but your response is very helpful moving forward- I really like the booktabs passage. Thank you again! – MathStudent1324 Aug 26 '18 at 1:41

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.