表格中的垂直线未对齐

表格中的垂直线未对齐

我正在尝试创建一个表格,但第一条垂直线不在正确的位置 - 表格的所有水平线都略微偏向垂直线的左侧。我该如何修复这个问题?(注意:我正在使用模板,因此虽然我认为大部分序言对这个表格没有影响,但我决定将其保留,以防出现我不知道的故障。)

我使用tabular*本文描述的环境:https://en.wikibooks.org/wiki/LaTeX/Tables。当我使用普通表格环境时,我没有这个对齐问题,但我想调整列的宽度,我不相信这是表格环境中的选项。

预先感谢您的帮助!

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

答案1

您可以使用 制作表格tabularx,这没有问题。我还对代码进行了一些改进和简化:

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

在此处输入图片描述

答案2

您发现tabular*其实并不喜欢表格中的垂直规则(我也不喜欢)。

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

注意代码的设置headheight和调整fancyhdr。另外,请注意,表不必放在table环境中:您希望该表那里,无标题。

在此处输入图片描述

不同的认识booktabs。你可以判断。

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

在此处输入图片描述

相关内容