섹션 스타일을 제어하여 모든 섹션 앞에 수평선을 추가하는 방법

섹션 스타일을 제어하여 모든 섹션 앞에 수평선을 추가하는 방법

이렇게 모든 섹션 앞에 수평선을 추가하고 싶습니다.

여기에 이미지 설명을 입력하세요

수동으로 모든 섹션 앞에 넣을 수도 있지만 \rule{\textwidth}{1pt}, 이를 달성하기 위해 섹션 스타일을 제어하기 위해 서문에 여러 코드를 넣는 등의 보다 유연한 방법이 필요합니다.

답변1

첫 번째 섹션 이전이나 페이지 상단에서 섹션이 시작될 때 규칙을 적용하는 것을 원하지 않을 것입니다. 다음 코드는 이를 수행합니다.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}

\usepackage{lipsum}

\titleformat{\section}
  {\sectionrule\Large\bfseries}
  {\thesection}
  {1em}
  {}

% this command is executed at each \section command
\newcommand{\sectionrule}{%
  % no rule before the first section
  \ifnum\value{section}=0
  \else
    % otherwise, ensure being between paragraphs
    \par
    % add some vertical space
    \addvspace{\bigskipamount}%
    % the rule realized as leaders, so it disappears at a page break
    % see also http://tex.stackexchange.com/a/61643/4427
    \leaders\vrule width \textwidth\vskip0.4pt
    % some other vertical space
    \bigskip
  \fi
}


\begin{document}

\section{First}

\lipsum[1-3]

\section{Second}

\lipsum[2-6]\lipsum[2]\lipsum[2]

\section{Third}

\lipsum

\end{document} 

여기에 이미지 설명을 입력하세요

페이지 나누기가 발생할 경우 페이지 상단에 규칙을 적용하는 대체 솔루션입니다.

\documentclass{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{titlesec}

\usepackage{lipsum}

\titleformat{\section}
  {\sectionrule\Large\bfseries}
  {\thesection}
  {1em}
  {}

\newcommand{\sectionrule}{%
    \par
    \addvspace{\bigskipamount}%
    \hrule
    \nopagebreak
    \bigskip
}

\begin{document}

\section{First}

\lipsum[1-3]

\section{Second}

\lipsum[2-6]\lipsum[2]\lipsum[2]

\section{Third}

\lipsum

\end{document}

여기에 이미지 설명을 입력하세요

답변2

titlesec을 사용하면 쉽습니다.

\documentclass{article}% http://ctan.org/pkg/amsproc

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{titlesec}

\titleformat{\section}{\vbox{\rule{\linewidth}{0.8pt}}\bigskip\LARGE\bfseries}{\thesection}{1em}{}
\begin{document}
\begin{equation}
  v = \sqrt{2gl(\cos\phi_0 - \cos \phi)}
\end{equation}
\section{Section two}

\end{document} 

여기에 이미지 설명을 입력하세요

관련 정보