2

I don't understand why my lines aren't showing up or look funny in this minimal example

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{hhline}

\begin{document}

 \begin{center}
 \begin{tabular}{|cc|p{1in}|cc|p{1in}|cc|} \hhline{--~--~--}
 \multicolumn{2}{|c|}{\cellcolor{green!50!white}U.S.} &&\multicolumn{2}{|c|} 
 {\cellcolor{green!50!white}France}&&\multicolumn{2}{|c|} 
 {\cellcolor{green!50!white}Japan} \\ \hhline{--~--~--}
 \multicolumn{2}{|c|}{$8$} &&\multicolumn{2}{|c|}{$41\frac{1} 
 {3}$}&&\multicolumn{2}{|c|}{$260$} \\ %\hhline{--~--~--}
 \multicolumn{2}{|c|}{$9$} &&\multicolumn{2}{|c|}{$42\frac{2} 
 {3}$}&&\multicolumn{2}{|c|}{$270$} \\ \hhline{--~--~--}
 \end{tabular}
 \end{center}

 \end{document}

enter image description here

11
  • Your \hhline s are empty in the p[1in}columns, so it looks normal, except for a missing vertical line in the first row. What did you expect?
    – Bernard
    Dec 14, 2018 at 19:09
  • @Bernhard, why is it missing in row 1 I thought I put that there and what syntax would I use to include in the p{1in} columns? Dec 14, 2018 at 19:12
  • 1
    It is not missing when I compile. Maybe a problem with the pdf viewer. What happens when you zoom?
    – Bernard
    Dec 14, 2018 at 19:19
  • 2
    This is common and is viewer-dependent; not an issue with TeX and therefore off-topic.
    – Werner
    Dec 14, 2018 at 19:37
  • 1
    I use SumatraPDF, which the recommended viewer (it doesn't lock the .pdf, and understands the .sync files, so you can do direct and inverse search). Also, don't you have holes in some vertical rules?
    – Bernard
    Dec 14, 2018 at 19:38

4 Answers 4

0
  • It is not clear why you use define columns cor each sub-table and than in them multicolumn{2}{c}{...}. It should be sufficient to use just one ...
  • For better visibility of vertical rules in colored part of table you can increase thickness of rules. For example to 0.5pt.
  • For removing holes in vertical lines use for horizontal lines \hhline{|-|~|-|~|-|}
  • Vertical space around cells' contets can be increased by use of the cellspace package:
\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{cellspace, hhline}
\setlength\cellspacetoplimit{2pt}
\setlength\cellspacebottomlimit{2pt}

\begin{document}
    \begin{center}
\setlength\arrayrulewidth{0.5pt}
\begin{tabular}{|Sc|p{1in}|Sc|p{1in}|Sc|}
    \hhline{|-|~|-|~|-|}
\cellcolor{green!50!white}{U.S.} 
    &&  \cellcolor{green!50!white}{France}  
        &&  \cellcolor{green!50!white}{Japan}   \\ 
    \hhline{|-|~|-|~|-|}
$8$ &&  $41\frac{1}{3}$ &&  $260$               \\ %\hhline{-~-~-}
$9$ &&  $42\frac{2}{3}$ &&  $270$               \\ 
    \hhline{|-|~|-|~|-|}
\end{tabular}
    \end{center}
\end{document}

enter image description here

1

Your lines are visible, but it depends on the PDF viewer you're using. Some viewers snap elements to a grid which could cause some components to be overridden by other things. This is commonly the case when adding colour to tables.

enter image description here

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{hhline}

\begin{document}

\begin{center}
  \renewcommand{\arraystretch}{1.2}%
  \begin{tabular}{ | c | p{1in} | c | p{1in} | c | }
    \hhline{-~-~-}
    \cellcolor{green!50!white}U.S. && \cellcolor{green!50!white}France && \cellcolor{green!50!white}Japan \\
    \hhline{-~-~-}
    $8$ && $41\frac{1}{3}$ && $260$ \\
    $9$ && $42\frac{2}{3}$ && $270$ \\
    \hhline{-~-~-}
  \end{tabular}
\end{center}

\end{document}

As you can see, there is no need for two columns in your setup, since a single column suffices.

0

Taking into account the comments above and @Mico answer here-- https://tex.stackexchange.com/a/50355/197451-- added strut since the fractions were touching the horizontals

enter image description here

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{hhline}

\begin{document}
\newcommand\T{\rule{0pt}{2.6ex}}       % Top strut
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut
 \begin{center}
 \begin{tabular}{|cc|p{1in}|cc|p{1in}|cc|} \hhline{--~--~--}
 \multicolumn{2}{|c|}
 {\cellcolor{green!50!white}U.S.} 
                                &&\multicolumn{2}{|c|} 
                                  {\cellcolor{green!50!white}France}
                                  \T\B
                                                                        &&\multicolumn{2}{|c|} 
                                                                          {\cellcolor{green!50!white}Japan} \\ \hhline{*{8}{-}}
\multicolumn{2}{|c|}
 {\cellcolor{blue!20!white}$8$} 
                                &&\multicolumn{2}{|c|}
                                  {\cellcolor{blue!20!white}$41
                                  \frac{1}{3}$} \T\B
                                                                        &&\multicolumn{2}{|c|} 
                                                                          {\cellcolor{blue!20!white}$260$} \\ 
                                                                          \hhline{*{8}{-}}
\multicolumn{2}{|c|}
 {\cellcolor{red!10!white}$9$} 
                                &&\multicolumn{2}{|c|}
                                  {\cellcolor{red!10!white}$42
                                  \frac{2}{3}$} \T\B
                                                                        &&\multicolumn{2}{|c|} 
                                                                          {\cellcolor{red!10!white}$270$} \\ 
                                                                          \hhline{*{8}{-}}                                                                          
 \end{tabular}
 \end{center}
0

The environment {NiceTabular} of nicematrix has been created to address that problem. With this environment, the lines will not seem do disappear in some PDF viewers at some levels of zoom (and you will not see the thin white lines you see sometimes in some PDF viewers like SumatraPDF when you use colortbl or the key table of xcolor).

\documentclass{article}

\usepackage{nicematrix}

\begin{document}

\begin{center}
  \renewcommand{\arraystretch}{1.2}%
  \begin{NiceTabular}{|c|}[colortbl-like] \hline
    \cellcolor{green!50!white}U.S. \\ \hline
    $8$ \\
    $9$ \\ \hline
  \end{NiceTabular}
  \hspace{1in}
  \begin{NiceTabular}{|c|}[colortbl-like] \hline
    \cellcolor{green!50!white}France \\ \hline
    $41\frac{1}{3}$ \\
    $42\frac{2}{3}$ \\ \hline
  \end{NiceTabular}
  \hspace{1in}
  \begin{NiceTabular}{|c|}[colortbl-like] \hline
    \cellcolor{green!50!white}Japan \\ \hline
    $260$ \\
    $270$ \\ \hline
  \end{NiceTabular}
\end{center}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .