3

For weird reasons, my tables (as produced by my statistics software, Stata) have \cmidrule{3-6} whenever they should have \cmidrule{4-7}. In my statistics software I can change the cmidrule, by I can not change th span it produces.

As a fix I want to define a new command \cmidruleshiftedbyone which autimatically adds 1 to the start and the end of the span and passes this on to \cmidrule.

I don't understand how the arguments for \cmidrulecan be parsed and changed, otherwise I'd like to do something like

\documentclass{article}
\usepackage{booktabs}
%I know this wont work, I just have this to illustrate what I am trying to do:
\usepackage{calc}
\newcommand{\cmidruleshiftedbyone}[1]{\cmidrule{{#1}+{1-1}}
\begin{document}
  \begin{tabular}{ccc}
    1 & 2 & 3 \\\cmidruleshiftedbyone(lr){1-2} %I wan this to actually span 2-3
  \end{tabular}
\end{document}

1 Answer 1

4
\documentclass{article}
\usepackage{booktabs}
\newcommand{\cmidruleshiftedbyone}[1]{\cmidrulehelp#1\relax}
\def\cmidrulehelp#1-#2\relax{\cmidrule{\numexpr#1+1\relax-\numexpr#2+1\relax}}
\begin{document}
  \begin{tabular}{ccc}
    1 & 2 & 3 \\\cmidruleshiftedbyone{1-2} %I wan this to actually span 2-3
  \end{tabular}
\end{document}

enter image description here

6
  • 1
    This is great, except, when I have two cmidrules in one row, they are not vertically aligned. I assume this is an easy fix to, but weren't able to find it so far: \begin{tabular}{cccc} 1 & 2 & 3 & 4\\\cmidruleshiftedbyone{1-2}\cmidruleshiftedbyone{3-3} \end{tabular}
    – sheß
    Commented Aug 30, 2016 at 15:03
  • 1
    @sheß The problem is most strange. It appears even if, for example, \newcommand\cmidruleshiftedbyone[1]{\cmidrule{#1}}. I still do not have a fix. Commented Aug 30, 2016 at 16:24
  • 1
    I know, I also tried reducing the code further to figure out where it "begins", but I can't seem to make sense of it. Maybe this itself should become its own questions.
    – sheß
    Commented Aug 30, 2016 at 16:28
  • 1
    Turns out someone else had that question earlier: tex.stackexchange.com/questions/63355/…, yet that answer is beyond me
    – sheß
    Commented Aug 30, 2016 at 16:33
  • 1
    For me the, the problem is solved, as an update of the Statistics-software allowed me to solve the issue one step before this.
    – sheß
    Commented Aug 31, 2016 at 9:18

You must log in to answer this question.

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