4

Any clues on how to easily remove those lines? I read other articles explaining the use of 'cline' command, but couldn't get it working myself.

\begin{table}
\scalebox{0.85}{
\setlength{\tabcolsep}{10pt}
\begin{tabular}{|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|p{0.35cm}|}
    \hline
    bit & 15 & 14 & 13 & 12 & 11 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\ \hline
    ~   & ~  & ~  & ~  & ~  & ~  & ~  & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\
    \hline
\end{tabular}
}
\end{table}
3
  • By the way, you may also have look on the bytefield package
    – user31729
    Sep 21, 2014 at 19:20
  • Why do you insert ~ in the empty cells? It's not necessary to do so, really.
    – Mico
    Sep 21, 2014 at 21:30
  • That is correct. They're there as place-holders.
    – Slon
    Sep 21, 2014 at 23:05

2 Answers 2

7

Omitting the left | can be obtained by using a \multicolumn{1}{c|}{}, removing just the left | specifier.

The lower \hline has to be replaced by a column specific cline command, which has the argument {startcolumn-endcolum}, i.e.

\cline{2-17} since there are 17 columns, but only the last 16 should be underlined, omitting the first one, so start at column 2.

All columns contain the same width and specifier, so it's quicker to say

\begin{tabular}{|*{17}{p{0.35cm}|}} 

Mico made a useful comment: The ~ aren't needed at all!


\documentclass{article}

\usepackage{graphicx}%
\begin{document}


\begin{table}
\scalebox{0.85}{
\setlength{\tabcolsep}{10pt}
\begin{tabular}{|*{17}{p{0.35cm}|}}
    \hline
    bit & 15 & 14 & 13 & 12 & 11 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\ \hline
    \multicolumn{1}{c|}{~}   & ~  & ~  & ~  & ~  & ~  & ~  & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\
    \cline{2-17}%
\end{tabular}
}
\end{table}
\end{document}

enter image description here

Some automated solution:

\documentclass{article}

\usepackage{graphicx}%
\usepackage{forloop}

\newcounter{othercounter}
\newcounter{loopcounter}%

\begin{document}


\begin{table}
\scalebox{0.85}{%
\setlength{\tabcolsep}{10pt}
\begin{tabular}{|*{17}{p{0.35cm}|}}
    \hline
    bit & 15 & 14 & 13 & 12 & 11 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\ \hline
    \multicolumn{1}{c|}{~}   & ~  & ~  & ~  & ~  & ~  & ~  & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\
    \cline{2-17}%
\end{tabular}
}
\end{table}


\newcommand{\mybitbox}[2]{%
\begin{table}
\scalebox{#1}{
\setlength{\tabcolsep}{10pt}
\begin{tabular}{|*{#2}{p{0.35cm}|}}
    \hline
    bit \forloop[-1]{loopcounter}{\numexpr#2-2}{\number\value{loopcounter} > -1}{& \number\value{loopcounter} } \tabularnewline%
    \hline
    \multicolumn{1}{c|}{} \forloop[-1]{loopcounter}{\numexpr#2-2}{\number\value{loopcounter} > -1}{& } \tabularnewline
    \cline{2-\numexpr#2}%
\end{tabular}
}
\end{table}
}%


\forloop{othercounter}{10}{\number\value{othercounter} < 17}{%
  \mybitbox{0.85}{\number\value{othercounter}}%
}

\end{document}

enter image description here

1
  • Lovely, this works. I appreciate the explanation, thank you.
    – Slon
    Sep 21, 2014 at 19:05
2

The environment {NiceTabular} is similar to the standard {tabular} but adds some features. Among these features, the keys hvlines draws all the rules except in the empty corners, computed by the key corners.

\documentclass{article}
\usepackage{geometry}.
\usepackage{nicematrix}

\begin{document}

\begin{table}
\setlength{\tabcolsep}{6pt}
\begin{NiceTabular}{*{17}{w{c}{0.3cm}}}[hvlines,corners=SW] % SW : south-west
    bit & 15 & 14 & 13 & 12 & 11 & 10 & 9 & 8 & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0 \\ 
        & ~  & ~  & ~  & ~  & ~  & ~  & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ & ~ \\
\end{NiceTabular}
\end{table}

\end{document}

Output of the above code

You must log in to answer this question.

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