4

I'm having some trouble getting proper padding around my section headers inside minipages.

\documentclass{article}
\usepackage[explicit]{titlesec}

\newcommand\Vhrulefill{\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\titleformat{\section}{\bfseries\large}{}{0pt}{\noindent\Vhrulefill~#1~\Vhrulefill}

\begin{document}
    \begin{minipage}[t]{0.45\textwidth}
        \section{Introduction}
            Some content for the first section
        \section{One More Section}
            \begin{itemize}
                \item Item 1
                \item Item 2
            \end{itemize}
        \section{Another Section}
            Some text outside of a list here
        \section{Last section}
            \begin{itemize}
                \item One here
                \item One more
            \end{itemize}
    \end{minipage}%
    \hfill\vline\hfill
    \begin{minipage}[t]{0.45\textwidth}
        \section{Introduction}
            Some content for the first section
        \section{One More Section}
            \begin{itemize}
                \item Item 1
                \item Item 2
            \end{itemize}
        \section{Another Section}
            Some text outside of a list here
        \section{Last section}
            \begin{itemize}
                \item One here
                \item One more
            \end{itemize}
    \end{minipage}%
\end{document}

demo

There's too little spacing before "One More Section" and too much after.

When I try to adjust it with \titlespacing, it doesn't affect all the sections

1 Answer 1

6

Here are 3 solutions

  1. Using multicols environment from multicol package enter image description here

\documentclass{article}
\usepackage[explicit]{titlesec}
\usepackage{multicol}

\newcommand\Vhrulefill{\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\titleformat{\section}{\bfseries\large}{}{0pt}{\noindent\Vhrulefill~#1~\Vhrulefill}

\setlength\columnseprule{.4pt}
%\setlength\columnsep{12pt}
\begin{document}
\begin{multicols}{2}
\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}

%\columnbreak

\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}
\end{multicols}
\end{document}
  1. Using parbox command enter image description here

\documentclass{article}
\usepackage[explicit]{titlesec}

\newcommand\Vhrulefill{\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\titleformat{\section}{\bfseries\large}{}{0pt}{\noindent\Vhrulefill~#1~\Vhrulefill}

\begin{document}
\parbox[t]{0.45\textwidth}{%
\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}
}%
\hfill\vline\hfill
\parbox[t]{0.45\textwidth}{%
\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}
}
\end{document}
  1. A work around minipage it seems that we can't start a minipage with \section so we used \ (space) or ~ enter image description here

\documentclass{article}
\usepackage[explicit]{titlesec}

\newcommand*\thirdoffive[5]{#3}
\makeatletter
\newcommand*\mt{\vskip-\expandafter\thirdoffive\ttls@section\ }
\makeatother
\newcommand\Vhrulefill{\leaders\hrule height 0.7ex depth \dimexpr0.4pt-0.7ex\hfill\kern0pt}
\titleformat{\section}{\bfseries\large}{}{0pt}{\noindent\Vhrulefill~#1~\Vhrulefill}

\begin{document}
\begin{minipage}[t]{0.45\textwidth}\mt
\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}
\end{minipage}%
\hfill\vline\hfill
\begin{minipage}[t]{0.45\textwidth}\mt
\section{Introduction}
 Some content for the first section
\section{One More Section}
\begin{itemize}
   \item Item 1
   \item Item 2
\end{itemize}
\section{Another Section}
Some text outside of a list here
\section{Last section}
\begin{itemize}
    \item One here
    \item One more
\end{itemize}
\end{minipage}
\end{document}
1
  • 1
    You're amazing! I used your third solution.
    – Zout
    Mar 9, 2016 at 0:39

You must log in to answer this question.

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