为什么左对齐会在表格中留出空间?

为什么左对齐会在表格中留出空间?

我有这个:

\documentclass{article}

\usepackage{longtable, array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{longtable}{|L{0.2\textwidth}|L{0.2\textwidth}L{0.2\textwidth}L{0.2\textwidth}|}\hline
\multicolumn{1}{|c|}{\large Physical Properties} & 
\multicolumn{1}{c|}{\large Solid} & 
\multicolumn{1}{c|}{\large Liquid} & \multicolumn{1}{c|}{\large Gas} \\ \hline
Shape & Definite & Indefinite & Indefinite \\ \hline
Volume & Definite & Definite & Indefinite \\ \hline
Force of Attraction & Very Strong & Less than solid & Least \\ \hline
Fluidity & Doesn't flow & Can flow & Can blow \\ \hline
Compressibility & Can't be compressed & Can't be compressed & Highly compressed \\ \hline
Diffusion & Very Slow & Fast & Fastest \\ \hline
\end{longtable}

\end{document}

产生结果(不需要的空间以黄色标记): 在此处输入图片描述

最左列的项目左对齐(根据需要)但在开始之前留出一些空间。

如何修复?谢谢!

答案1

第一列的规定宽度小于\multicolumn其中单元格的宽度。更简单的补救措施是对此列使用自然宽度:

\documentclass{article}

\usepackage{array, longtable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}m{#1}}
\NewExpandableDocumentCommand\mcc{O{c|}m}{\multicolumn{1}{#1}{#2}}

\begin{document}
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{4pt}
\begin{longtable}{|l | *{3}{L{0.2\textwidth}|} }
    \hline
\large Physical Properties 
    &   \mcc{\large Solid} 
        & \mcc{\large Liquid} 
            & \mcc{\large Gas}                              \\ \hline
Shape       & Definite      & Indefinite    & Indefinite    \\ \hline
Volume      & Definite      & Definite      & Indefinite    \\ \hline
Force of Attraction 
            & Very Strong   & Less than solid 
                                            & Least         \\ \hline
Fluidity    & Doesn't flow  & Can flow      & Can blow      \\ \hline
Compressibility 
            & Can't be compressed 
                            & Can't be compressed 
                                            & Highly compressed \\ \hline
Diffusion   & Very Slow     & Fast          & Fastest           \\ \hline
\end{longtable}

\end{document}

在此处输入图片描述

我想知道,你真的需要longtable这个表格吗?如果它短于一页,使用tabularx表格是明智的(至少在我看来)。在这种情况下,你不需要注意表格不要太宽\textwidth

\documentclass{article}

\usepackage{tabularx}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\NewExpandableDocumentCommand\mcc{O{c|}m}{\multicolumn{1}{#1}{#2}}

\begin{document}

\setlength\extrarowheight{2pt}
\noindent
\begin{tabularx}{\linewidth}{|l | *{3}{L|} }
    \hline
\large Physical Properties 
    &   \mcc{\large Solid} 
        & \mcc{\large Liquid} 
            & \mcc{\large Gas}                              \\ \hline
Shape       & Definite      & Indefinite    & Indefinite    \\ \hline
Volume      & Definite      & Definite      & Indefinite    \\ \hline
Force of Attraction 
            & Very Strong   & Less than solid 
                                            & Least         \\ \hline
Fluidity    & Doesn't flow  & Can flow      & Can blow      \\ \hline
Compressibility 
            & Can't be compressed 
                            & Can't be compressed 
                                            & Highly compressed \\ \hline
Diffusion   & Very Slow     & Fast          & Fastest           \\ \hline
\end{tabularx}

\end{document}

结果和以前几乎一样。

附录: 如果表格长度超过一页,您可以考虑使用xltabular表格。除此之外,考虑到下面评论中的问题,使用makecellbooktabs包,没有垂直规则:

\documentclass{article}

\usepackage{booktabs, makecell, xltabular}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadgape{}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}

\begin{document}

\begingroup
\setcellgapes{2pt}
\makegapedcells
\normalsize\linespread{0.84}\selectfont
\begin{xltabular}{\linewidth}{ L{1.15} *{3}{L{0.95}} }
    \toprule
\thead[l]{Physical\\ Properties} 
    &   \thead[l]{Solid} 
        & \thead[l]{Liquid} 
            & \thead[l]{Gas}                              \\ 
    \midrule
Shape       & Definite      & Indefinite    & Indefinite    \\ 
Volume      & Definite      & Definite      & Indefinite    \\ 
    \addlinespace
Force of Attraction 
            & Very Strong   & Less than solid 
                                            & Least         \\ 
Fluidity    & Doesn't flow  & Can flow      & Can blow      \\ 
    \addlinespace
Compressibility 
            & Can't be compressed 
                            & Can't be compressed 
                                            & Highly compressed \\ 
Diffusion   & Very Slow     & Fast          & Fastest           \\ 
    \bottomrule
\end{xltabular}
\endgroup

\end{document}

在此处输入图片描述

答案2

您必须增加第一列的宽度。

\documentclass{article}

\usepackage{longtable, array}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}

\begin{document}

\begin{longtable}{|L{0.3\textwidth}|L{0.2\textwidth}L{0.2\textwidth}L{0.2\textwidth}|}
\hline
\multicolumn{1}{|c|}{\large Physical Properties} & 
\multicolumn{1}{c|}{\large Solid} & 
\multicolumn{1}{c|}{\large Liquid} & \multicolumn{1}{c|}{\large Gas} \\ \hline
Shape & Definite & Indefinite & Indefinite \\ \hline
Volume & Definite & Definite & Indefinite \\ \hline
Force of Attraction & Very Strong & Less than solid & Least \\ \hline
Fluidity & Doesn't flow & Can flow & Can blow \\ \hline
Compressibility & Can't be compressed & Can't be compressed & Highly compressed \\ \hline
Diffusion & Very Slow & Fast & Fastest \\ \hline
\end{longtable}

\end{document}

相关内容