使用 titlesec 管理小页面内 \section 周围的间距

使用 titlesec 管理小页面内 \section 周围的间距

我在为小页面中的部分标题设置适当的填充时遇到了一些麻烦。

\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}

演示

“再多一个部分”之前的间距太小,而之后的间距太大。

当我尝试使用 进行调整时\titlespacing,它不会影响所有部分

答案1

以下是 3 种解决方案

  1. 使用包 multicols中的环境multicol在此处输入图片描述

\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. 使用parbox命令 在此处输入图片描述

\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. 解决办法minipage似乎是我们无法启动迷你页面,\section所以我们使用\(空格)或~ 在此处输入图片描述

\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}

相关内容