TransWikia.com

Parbox on the table not vertically centered and remove space before enumeration but topsep=0pt failed

TeX - LaTeX Asked on December 22, 2020

My problems:

  1. I’m using parbox to give line break on the table but not vertically centered. If you zoom in on the head of the table, you’ll see it’s centered on the bottom, but i want it on the middle. (Goal: vertically centered).
  2. line start of the enumeration is different with the line start of the text. Seems like there’s a vertical space before the list, and i want to remove that. Using topsep=0pt give me nothing. (Goal: the same line start).

This is my MWE:

documentclass[a4paper,12pt,oneside,openany]{book}
usepackage[a4paper, inner=4cm, outer=3cm, top=4cm, bottom=3cm]{geometry}
usepackage{longtable}
usepackage{lipsum}
usepackage{pdflscape}
renewcommand{arraystretch}{2.0}
usepackage{enumitem}

begin{document}
    chapter{BOO}
    lipsum[1-2]
    newpage
    thispagestyle{plain}
    begin{landscape}
        section{My Table}
        begin{table}[h!]
            centering
            caption{This is a table}
            begin{tabular}{|p{3cm}| p{3cm} |p{3cm}|p{3.2cm}|p{2.5cm}|p{2.5cm}|p{3cm}|}
                hline
                multicolumn{1}{|c|}{textbf{Whatever}} 
                & multicolumn{1}{c|}{parbox[H]{3cm}{centering textbf{Random  Text}}} 
                & multicolumn{1}{c|}{textbf{Whatever}} 
                & multicolumn{1}{c|}{textbf{Whatever}} 
                & multicolumn{1}{c|}{parbox[H]{2cm}{centering textbf{Random  Text}}} 
                & multicolumn{1}{c|}{parbox[H]{3cm}{centering textbf{Random  Text}}}
                & multicolumn{1}{c|}{parbox[H]{3cm}{centering textbf{Random  Text}}}
                hline
                lipsum[2][1]
                & begin{enumerate}[left= 0pt, label=arabic*), noitemsep, topsep= 0pt]
                    item lipsum[1][1]
                    item lipsum[1][1]
                end{enumerate} 
                & begin{enumerate}[left= 0pt, label=arabic*), noitemsep, topsep= 0pt]
                    item lipsum[1][1]
                    item lipsum[1][1]
                end{enumerate} 
                &begin{enumerate}[left= 0pt, label=arabic*), noitemsep, topsep= 0pt]
                    item lipsum[1][1]
                    item lipsum[1][1]
                end{enumerate}
                &begin{enumerate}[left= 0pt, label=arabic*), noitemsep, topsep= 0pt]
                    item lipsum[1][1]
                end{enumerate}
                &lipsum[2][4]
                & lipsum[2][1]
                hline
            end{tabular}
        end{table}
    end{landscape}
    
end{document}

Help me please. Thanks!

One Answer

To fix the first issue, I suggest you load the makecell package and use makecell{...} directives instead of multicolumn{1}{c|}{parbox[H]{3cm}{centering ...}} wrappers.

To fix the second issue, I suggest you make use of some of the enumitem package's machinery -- specifically, its newlist and setlist directives -- to create a bespoke enumerate-like list environment (called ColEnum in the example code below) that encases the list's contents in a minipage. Doing so will strip off the vertical whitespace.

I would also like to suggest that you use RaggedRight directives in the narrow columns, to switch from full justification to ragged-right.

enter image description here

documentclass[a4paper,12pt,oneside,openany]{book}
usepackage[inner=4cm, outer=3cm, top=4cm, bottom=3cm]{geometry}
usepackage{lipsum,pdflscape}

% new:
usepackage{makecell} % for 'makecell' macro
usepackage{ragged2e} % for 'RaggedRight' macro
usepackage{enumitem} % for 'newlist' and 'setlist' macros
newlist{ColEnum}{enumerate}{1}
setlist[ColEnum,1]{label = arabic*), left = 0pt, nosep, 
          before= {begin{minipage}[t]{hsize}RaggedRight},
          after = {end{minipage}}}

begin{document}
setcounter{chapter}{2} % just for this example
thispagestyle{plain}
begin{landscape}
section{A section header, followed by a table}

begin{table}[h!]
centering
caption{This is a tablestrut}
begin{tabular}{|p{3cm}   | p{3cm}   | p{3cm}   |
                 p{3.2cm} | p{2.5cm} | p{2.5cm} | p{3cm}|}
hline
bfseriesmakecell{Whatever}  & 
bfseriesmakecell{Random  Text} & 
bfseriesmakecell{Whatever} & 
bfseriesmakecell{Whatever} & 
bfseriesmakecell{Random  Text} & 
bfseriesmakecell{Random  Text} & 
bfseriesmakecell{Random  Text} 
hline
RaggedRightlipsum[2][1] & 
begin{ColEnum}
   item lipsum[1][1]
   item lipsum[1][1]
end{ColEnum} & 
begin{ColEnum}
   item lipsum[1][1]
   item lipsum[1][1]
end{ColEnum} &
begin{ColEnum}
   item lipsum[1][1]
   item lipsum[1][1]
end{ColEnum} &
begin{ColEnum}
   item lipsum[1][1]
end{ColEnum} &
RaggedRightlipsum[2][4] & 
RaggedRightlipsum[2][1] 
hline
end{tabular}
end{table}
end{landscape}
    
end{document}

Correct answer by Mico on December 22, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP