TransWikia.com

Problem with vertical spacing in table

TeX - LaTeX Asked by BennyS on January 20, 2021

Objective

I want to create a simple n x 1 table with a thick colored border on the left side.

My approach

documentclass{article}
usepackage{amsmath}
usepackage{tabularx}
usepackage{array,booktabs,arydshln,xcolor,colortbl}
newcommandVRule[1][arrayrulewidth]{vrule width #1}


begin{document}
LARGE
begin{tabular}{!{color{blue!70}VRule[4pt]}m{4cm}}
{ABC}
{DEF}
{GHI}
{JKL}
{MNO}
{PQRS}
end{tabular}


end{document}

Result1:

Example 1

Result2 (using NiceMatrix):

Example 2

Problem

Since I am using latex because I like the correct and clean look, some minor things dont please me.

  • The border shows "visual" separations of the rows. This is an effect of Large. I can get rid of this using nicematrix package. However this is just a workaround in my opinion. Moreover, the border is extended even more (see result2)
  • The Cells are not centered vertically in their cells in my opinion.(See Image1) In my opinion, there is more space between table bottom to the lower cell content and the table top to the top of the upper cell content.

I already did some research but none of the solutions in the internet solved my problem. Using NiceTabular gets rid of problem #1, but the spacing problem still remains.

2 Answers

Two examples: left a wee bit modified your code, right with use of the nicematrix:

documentclass{article}
usepackage{array}
usepackage[table]{xcolor}
usepackage{nicematrix}

begin{document}
LARGE
arrayrulecolor{blue!70}
setlength{arrayrulewidth}{4pt}
begin{tabular}{| l<{vphantom{Q}}}
    ABC     
    DEF     
    GHI     
    JKL     
    MNO     
    PQRS    
end{tabular}
quad
begin{NiceTabular}{|l<{vphantom{Q}}}
    ABC     
    DEF     
    GHI     
    JKL     
    MNO     
    PQRS    
end{NiceTabular}
end{document}

enter image description here

Why the blue line is at NiceTabular longer, we should ask author of package: @F. Pantigny ...

Answered by Zarko on January 20, 2021

Depending on the intended se case, a simple tabular inside of a tcolorbox could be an alternative apporach:

enter image description here

documentclass{article}

usepackage[most]{tcolorbox}
newtcolorbox{mybox}{
    enhanced,
    hbox,
    boxrule=0pt,
    frame hidden,
    borderline west={4pt}{0pt}{blue!70},
    colback=white,
    sharp corners, 
    boxsep=0pt
    }

begin{document}

begin{mybox}
begin{tabular}{@{}l}
ABC
DEF
GHI
JKL
MNO
PQRS
end{tabular}
end{mybox}

end{document}

Answered by leandriis on January 20, 2021

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