1

So I was reading this answer and liked the result with tcolorbox:

https://tex.stackexchange.com/a/271436/98870

The solution is to effectively use the following code:

\begin{tcolorbox}[
    blanker,
    width=0.64\textwidth,enlarge left by=0.36\textwidth,
    before skip=6pt,
    breakable,
    overlay unbroken and first={%
    \node[inner sep=0pt,outer sep=0pt,text width=0.33\textwidth,
    align=none,
    below right]
    at ([xshift=-0.36\textwidth]frame.north west)
{ 
    LEFT COLUMN TEXT
  };}]
    RIGHT COLUMN TEXT
\end{tcolorbox}

The answer insists

If needed, everything could be put into a macro or environment for a nicer interface.

But I am unsure on how to do this. I assumed it meant an environment like this

\begin{twocolumns}
   LEFT COLUMN TEXT
   \nextcolumn
   RIGHT COLUMN TEXT
\end{twocolumns}

But I don't see how to do this easily with the \newenvironment{} command due to the use of the braces throughout the solution (e.g. the \nextcolumn" command would amount to the closing of the node with the line };}]). Any help with getting it into this above form or something more usable (is there a better idea? not sure!) is greatly appreciated!

1 Answer 1

1

Here are two options. Both of the example documents render the same output:

New macro

You could define a macro with two arguments, one for each of the two columns.

\documentclass{article}
\usepackage[skins,breakable]{tcolorbox}
\newcommand{\twocolumnsbox}[2]{%
    \begin{tcolorbox}[
        blanker,
        width=0.64\textwidth,enlarge left by=0.36\textwidth,
        before skip=6pt,
        breakable,
        overlay unbroken and first={%
        \node[inner sep=0pt,outer sep=0pt,text width=0.33\textwidth,
        align=none,
        below right]
        at ([xshift=-0.36\textwidth]frame.north west)
    { 
        #1
      };}]
        #2
    \end{tcolorbox}%
}
\begin{document}

\twocolumnsbox{Left column text}{Right column text}

\end{document}

New environment

You could also define a new environment taking the left column text as an argument, and placing the right column text inside of the environment.

\documentclass{article}
\usepackage[skins,breakable]{tcolorbox}
\newenvironment{twocolumns}[1]{
    \begin{tcolorbox}[
        blanker,
        width=0.64\textwidth,enlarge left by=0.36\textwidth,
        before skip=6pt,
        breakable,
        overlay unbroken and first={%
        \node[inner sep=0pt,outer sep=0pt,text width=0.33\textwidth,
        align=none,
        below right]
        at ([xshift=-0.36\textwidth]frame.north west)
    { 
        #1
      };}]%
    }{%
    \end{tcolorbox}%
}
\begin{document}

\begin{twocolumns}{Left column text}
Right column text
\end{twocolumns}

\end{document}
2
  • This is great, thanks! A question out of curiosity: which way is preferred, or is this more of a user's choice than there being an obvious one?
    – anak
    May 10, 2020 at 20:30
  • @anakhro As far as I know, it is only a matter of preference. I think I'd use the environment, especially if there is not so much text of the left column.
    – Vincent
    May 10, 2020 at 20:38

You must log in to answer this question.

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