[Tex/LaTex] Show frame/margin in two column layout

marginstwo-column

How can I show the frames for inter-column margin under the twocolumn document class option?

The showframe package only draws the page margins + headers and footers. But I want to see a line for the margin between two columns.

Best Answer

One option using \@outputdblcol:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{showframe}

\newlength\Fcolumnseprule
\setlength\Fcolumnseprule{0.4pt}

\makeatletter
\def\@outputdblcol{%
  \if@firstcolumn
    \global \@firstcolumnfalse
    \global \setbox\@leftcolumn \box\@outputbox
  \else
    \global \@firstcolumntrue
    \setbox\@outputbox \vbox {%
                         \hb@xt@\textwidth {%
                           \hb@xt@\columnwidth {%
                             \box\@leftcolumn \hss}%
                           \vrule \@width\Fcolumnseprule\hfil
                                {\normalcolor\vrule \@width\columnseprule}%original:
                                                %\normalcolor\vrule \@width\columnseprule
                           \hfil\vrule \@width\Fcolumnseprule
                           \hb@xt@\columnwidth {%
                             \box\@outputbox \hss}%
                                             }%
                              }%
    \@combinedblfloats
    \@outputpage
    \begingroup
      \@dblfloatplacement
      \@startdblcolumn
      \@whilesw\if@fcolmade \fi
        {\@outputpage
         \@startdblcolumn}%
    \endgroup
  \fi
}
\makeatother


\begin{document}

\lipsum[1-30]

\end{document}

enter image description here

A patch makes the code shorter:

\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{showframe}
\usepackage{etoolbox}

\newlength\Fcolumnseprule
\setlength\Fcolumnseprule{0.4pt}

\makeatletter
\newcommand\ShowInterColumnFrame{
\patchcmd{\@outputdblcol}
  {{\normalcolor\vrule \@width\columnseprule}}
  {\vrule \@width\Fcolumnseprule\hfil
    {\normalcolor\vrule \@width\columnseprule}
    \hfil\vrule \@width\Fcolumnseprule
  }
  {}
  {}
}

\makeatother
\ShowInterColumnFrame

\begin{document}

\lipsum[1-30]

\end{document}
Related Question