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

MathScholar
  • 2,513

4 Answers4

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.

Werner
  • 603,163
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}
js bibra
  • 21,280
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

Zarko
  • 296,517
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

F. Pantigny
  • 40,250