2

I have this:

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

which produces (the unwanted spaces are marked in yellow): enter image description here

The items in the leftmost column are aligned to the left (as wanted) but leave some space before beginning.

How to fix this? Thanks!

1
  • @JohnKormylo Could you please add an answer? I tried but it shows an error saying Misplaced \omit (due to the \multicolumn maybe?) Apr 12, 2021 at 12:27

2 Answers 2

3

Prescribed width of the first column is smaller than width of the \multicolumn cell in it. Simpler remedy is to use natural width for this column:

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

enter image description here

I wonder, if you really need longtable for this table? If it is shorter than one page, is sensible (at least to my opinion) to use tabularx table. In this case you not need to take a care that table is not wider to \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}

Result is almost the same as before.

Addendum: If table is longer than one page, you may consider to use xltabular table. Beside this, considering your question in comment below, use makecell and booktabs packages, without vertical rules:

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

enter image description here

3
  • Actually, this table is a part of a bigger project, so I use longtables to be carefree of pagebreaks. Apr 12, 2021 at 14:06
  • I just wanted to ask, how do I manage if there is an item in left most column that exceeds the width of Physical Properties, taking into account I don't want the text area to increase further? Apr 12, 2021 at 14:13
  • @BookOfFlames, that is mater of personal preference. I would design your table quite differently: without vertical lines, with rules defined in the booktabs package and for column headers use makecell package enabling two line text in them and also not increase font size in the columns headers.
    – Zarko
    Apr 12, 2021 at 14:20
2

You must increase width of first column.

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

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.