2

I'm trying to create an environment within a twocolumn document which behaves differently depending on which column it's in. Specifically, I'm making a tcolorbox, which is supposed to stretch to the edge of the page, which may be either left or right depending on the column the box is placed in. However, for this question, the conditioning is of importance.

In order to do that I've tried using the \if@firstcolumn command.

\documentclass[a4paper, 11pt, twocolumn, twoside]{book}
\usepackage{lipsum}

\usepackage{geometry}
\geometry{a4paper, includeheadfoot,top=0cm, bottom=0cm, headheight=2cm, headsep=0.1cm, footskip=2cm, left=1cm, right=1cm}

\newenvironment{columnbox}{\par\bfseries
  \if@firstcolumn FIRST \else SECOND \fi
}{COLUMN\par}

\begin{document}
\pagestyle{empty}
\lipsum[1]
\begin{columnbox}
\end{columnbox}
\lipsum
\begin{columnbox}
\end{columnbox}
\lipsum
\begin{columnbox}
\end{columnbox}
\lipsum
\begin{columnbox}
\end{columnbox}
\end{document}

This, however, does not work; instead of giving out the correct value, it gives the \else value no matter which column it's in.

I suspect I've misunderstood the way it gets evaluated and it gets checked (and fixed to false, since there's no column?) in the preamble already, instead of being checked any time the environment is called, as I'd hoped.

What would be the correct way to achieve what I'm trying to do?

1

1 Answer 1

2

Since the conditional is \if@firstcolumn, you need to surround your environment definition with a \makeatletter...\makeatother pair:

\makeatletter
\newenvironment{columnbox}{% \begin{columnbox}
  \par\bfseries
  \if@firstcolumn FIRST \else SECOND \fi
}{% \end{columnbox}
  COLUMN\par
}
\makeatother
1
  • That did it. And it's one of those 'Slap myself for forgetting about that.' answers. Thanks.
    – Suthek
    Jan 5, 2020 at 1:05

You must log in to answer this question.

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