Graphics, Figures & TablesTable with unequal columns

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Table with unequal columns

Post by jaybz »

I need to add a row to my table at the top but it only needs to be 4 columns wide which are aligned to the right. The additional row should also have a extra thick horizontal line the same thickness as what I have in my code now. It should have one extra thick vertical line to the left and skinny vertical lines everywhere else. I also need colored lines.

Code: Select all

    \documentclass{article}
    \usepackage{array}
    \begin{document}
    \begin{center}
      \renewcommand{\arraystretch}{1.3}
      \begin{tabular}{!{\vrule width 2pt}c!{\vrule width 2pt}c|c|c|c
      |c|c|c|c|}
        \noalign{\hrule height 2pt}
        10 & 1.22 & 5.64 & 4.12 & 1.27  \\ \hline
        20 & 3.15 & 4.34 & 1.16 & 6.10  \\ \hline
        50 & 6.46 & 3.52 & 5.23 & 2.12  \\ \hline
        70 & 7.25 & 8.16 & 7.56 & 3.44  \\ \hline
        100 & 4.31 & 2.11 & 1.45 & 4.17 \\ \hline
        \end{tabular}
    \end{center}
    \end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Table with unequal columns

Post by Stefan Kottwitz »

Hi,
  • to skip a column you can use \multicolum. It's intended for merging cells, but can be used to produce cells with different formatting. Here, for example:

    Code: Select all

    \multicolumn{1}{c!{\vrule width 2pt}}{}& 10 & 20 & 30 & 40  \\ \hline
  • For drawing horizontal lines spanning not all columns, you can use \cline:

    Code: Select all

    \cline{2-5}
  • The thickness of tabular lines is defined by \arrayrulewidth, you can change it:

    Code: Select all

    \setlength{\arrayrulewidth}{2pt}
  • For colored lines use the colortbl package and its commands such as
    \arrayrulecolor{blue}:

    Code: Select all

    \usepackage[table]{xcolor}
    or

    Code: Select all

    \usepackage{colortbl}
Btw. I don't like framing all cells in a table, it's hardly readable. I know from good books that using just horizontal lines, supporting reading, is good style, but not using vertical lines. If you need all those lines, then of course it's ok, it's just a general side note.

Here are examples and information on tables: Creating tables with LaTeX.

Stefan
LaTeX.org admin
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Table with unequal columns

Post by jaybz »

I'm getting there, have the following:

Code: Select all

    \documentclass{article}
    \usepackage{array}
    \usepackage{colortbl}
    \begin{document}
    \begin{center}
      \renewcommand{\arraystretch}{1.3}
      \setlength{\arrayrulewidth}{0.5pt}
      \arrayrulecolor{blue}
      \begin{tabular}{!{\color{blue}\vline width 2pt}
c!{\color{blue}\vline width 2pt}c|c!{\color{blue}\vrule width 0.5pt}c|c|}
        \noalign{\hrule height 2pt}
        ~ & 1.11 & 1.11 & 1.11 & 1.11  \\  \hline
        10 & 1.23 & 2.55 & 6.26 & 3.09  \\ \hline 
        20 & 3.10 & 3.22 & 4.32 & 3115  \\ \hline
        40 & 4.22 & 5.16 & 4788 & 7.35  \\ \hline
        70 & 5.35 & 7.18 & 3.74 & 8.65  \\ \hline
        100 & 5.79 & 5.24 & 1.47 & 5.88 \\ \hline
        \end{tabular}
    \end{center}
    \end{document}
The arrayrulecolor cmd wasn't working for the vertical lines so I just used the color command for the "|"
The top line should be blue, then the line bellow the cells with "1.11" in them, should be 2pt as well. Also for the cell above "10" there shouldn't be a left, or top line.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: Table with unequal columns

Post by jaybz »

Can someone please help with this ? I don't understand how to use multicolum and leave out the upper left cell.
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Table with unequal columns

Post by jaybz »

I'm very close to getting it now but how can I make a thick line just below the "1 2 3 4 5" Also the line above the "10" thick as well?

Code: Select all

\documentclass{article}
\usepackage{array}
\usepackage{colortbl}
\newlength{\arrayrulewidthOriginal}
\newcommand{\Cline}[2]{%
  \noalign{\global\setlength{\arrayrulewidthOriginal}{\arrayrulewidth}}%
  \noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
  \noalign{\global\setlength{\arrayrulewidth}{\arrayrulewidthOriginal}}}
\begin{document}
\begin{center}
\renewcommand{\arraystretch}{1.3}
\arrayrulecolor{blue}
\begin{tabular}{!{\color{blue}\vline width 2pt}c!{\color{blue}\vline width 2pt}c|c|c|c|c|c|}
\Cline{2pt}{2-6} 
\multicolumn{1}{c!{\color{blue}\vline width 2pt}}{} & 1 & 2 & 3 & 4 & 5\tabularnewline
\hline 
10 & 1 & 5 & 4 & 8 & 5\tabularnewline
\hline 
20 & 4 & 7 & 6 & 2 & 4\tabularnewline
\hline 
30 & 1 & 8 & 5 & 3 & 1\tabularnewline
\hline 
40 & 3 & 5 & 4 & 2 & 7\tabularnewline
\hline
\end{tabular}
\end{center}
\end{document}
jaybz
Posts: 90
Joined: Sun Jul 11, 2010 6:02 pm

Re: Table with unequal columns

Post by jaybz »

I believe the simplest solution here would be to define a command for a new hline like with the cline but I don't know how to do it. I got the code for the cline on the forums here but I don't understand it. Can someone please show me how?
Post Reply