20

How can I produce \noalign{\hrule height 1pt} only through a certain number of columns just like with \cline{n-m} (or basically \cline with adjustable thickness)?

The objective.

Fig. 1: The approximate objective (digitally manipulated in a graphics editing program).

3 Answers 3

27

You can define a new command which changes the value of \arrayrulewidth, draws the \cline and then restores \arrayrulewidth to its original value:

\documentclass{book}

\newlength{\Oldarrayrulewidth}
\newcommand{\Cline}[2]{%
  \noalign{\global\setlength{\Oldarrayrulewidth}{\arrayrulewidth}}%
  \noalign{\global\setlength{\arrayrulewidth}{#1}}\cline{#2}%
  \noalign{\global\setlength{\arrayrulewidth}{\Oldarrayrulewidth}}}
\begin{document}

\begin{tabular}{ccc}
  a & b & c \\\Cline{2pt}{2-3}
  d & e & f \\\Cline{3pt}{1-2}
\end{tabular}

\end{document}

enter image description here

The first argument of \Cline controls the "thickness" of the rule.

EDIT: The \cmidrule command provided by the booktabs package admits an optional argument controlling the thickness of the rule, so you can say:

\documentclass{book}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{ccc}
  a & b & c \\ \cmidrule[2pt]{2-3}
  d & e & f \\ \cmidrule[3pt]{1-2}
\end{tabular}

\end{document}
3
  • 1
    Unfortunately, this does not seem to have any effect when used with the \multirow command from the multirow package. Dec 19, 2014 at 9:57
  • 1
    If I load the mathtools package, this doesn't seem to work... any ideas?
    – cmhughes
    Mar 15, 2015 at 18:15
  • Creating a new command is an elegant solution, and avoids using yet another package. booktabs is a good solution, provided you don't use vertical lines, which the package creator refuses to implement.
    – Francisco
    Jun 7, 2018 at 12:23
4

You may have a look at the tabu package. It supports optional parameters for the width of the rules in a table.

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage{multirow,tabu}
\usepackage{graphicx}

\newcommand*{\rb}[1]{\raisebox{2ex}{\smash{#1}}}
\setlength{\extrarowsep}{10pt}

\begin{document}
  \scriptsize
  \noindent
  \begin{tabu} to \textwidth {|[1pt] c|[1pt] c|[1pt] p{4cm} | X |[1pt]}\tabucline[1pt]{-}
    \multirow{4}{*}[-5ex]{\rotatebox{90}{Ten}} & \multirow{2}{*}[-2ex]{\rotatebox{90}{Eight}} & \rb{One} & \rb{Two} \\ \tabucline{3-4}
    & & \rb{Three} & \rb{Four} \\[2ex] \tabucline[1pt]{2-4}
    & \multirow{2}{*}[-2ex]{\rotatebox{90}{Nine}} & \rb{Five} & \rb{Six} \\ \tabucline{3-4}
    & &\multicolumn{2}{l|[1pt]}{\rb{Seven}} \\[4ex] \tabucline[1pt]{-}
  \end{tabu}
\end{document}
3
  • I am indeed impressed by your solution of almost all issues I currently have. It is unfortunate that I did not come across the tabu package before, it looks very promising. There is just one more issue: If I want some of the rules thicker (as in your code), there are gaps between them. Do you know how to make them join seamlessly, please? Jul 31, 2011 at 15:38
  • I see what you mean. And I'm afraid that this is an issue that is better addressed to the package maintainer. Jul 31, 2011 at 15:42
  • I have just accidentally solved it by simply replacing \tabucline with \cline and \Cline defined by @Gonzalo Medina hereinbefore. Thank you very much! Jul 31, 2011 at 16:05
3

With package colortbl , you may redefine the thickness of \hline and \cline.

The example below is adapted from page 6 of the manual for colortbl:

\documentclass{book}
\usepackage{colortbl}        
\begin{document}
\setlength\arrayrulewidth{2pt}\arrayrulecolor{blue}

  \begin{tabular}{cc}
      \hline
          one   & two\\
          three & four\\
      \cline{1-1}
  \end{tabular}

\end{document}

enter image description here

2
  • Is it possible to use this answer just for one \clie in one table, and don't change other lines and other tables? \setlength\arrayrulewidth{2pt}\arrayrulecolor{blue}
    – Reza
    Feb 17, 2021 at 8:24
  • 1
    The color can be changed within a table using \arrayrulecolor{myColor} anywhere in the table. The thickness seems to be set for the entire table. See documentation of colortbl.
    – Themis
    Feb 18, 2021 at 11:58

You must log in to answer this question.

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