센터링 섹션

센터링 섹션

titlesec 다음과 같이 섹션을 중앙에 배치하는 데 사용하고 싶습니다 (MWE).

\documentclass[10pt,a4paper,twoside]{book}
\usepackage[latin1]{inputenc}
\usepackage{lipsum}
\usepackage{titlesec}
\titleformat{\section}% command to format the section titles
        [block]% shape/type of title
        {\LARGE\bfseries}% formatting commands applied to both label and title
        {\begin{center} \thesection \end{center}}% section number; here set inside an invisible box with a constant width
        {0em}% separation between number and chapter title; we've already covered this with the box
        {}% additional formatting command for title itself not applied to number
        [
        ]%
\begin{document}
\chapter{The first chapter}
\lipsum[1-5]
\section{First section}
\lipsum[3]
\section*{Section}
\lipsum[4]

\end{document}

그러나 이것은 섹션 제목의 중앙에 위치하지 않으며 그다지 아름답지도 않습니다. 을 사용하여 섹션을 중앙에 아름답게 배치하려면 어떻게 해야 합니까 titlesec?

답변1

cfr이 제안한대로 \centering사용 하면 작동합니다 .\LARGE\bfseries

\titleformat{\section}% command to format the section titles
        [block]% shape/type of title
        {\LARGE\bfseries\centering}% formatting commands applied to both label and title
        {\thesection}% section number; here set inside an invisible box with a constant width
        {1ex}% separation between number and chapter title; we've already covered this with the box
        {}% additional formatting command for title itself not applied to number
        [
        ]%

준다

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

단순화된 형식을 사용할 수도 있습니다.

\titleformat*{\section}{\LARGE\bfseries\centering}

대신에 \titleformat.

\documentclass[10pt,a4paper,twoside]{book}
\usepackage[latin1]{inputenc}
\usepackage{lipsum}
\usepackage{titlesec}
%\titleformat{\section}% command to format the section titles
%        [block]% shape/type of title
%        {\LARGE\bfseries\centering}% formatting commands applied to both label and title
%        {\thesection}% section number; here set inside an invisible box with a constant width
%        {1ex}% separation between number and chapter title; we've already covered this with the box
%        {}% additional formatting command for title itself not applied to number
%        [
%        ]%

\titleformat*{\section}{\LARGE\bfseries\centering}
\begin{document}
\chapter{The first chapter}
\lipsum[1-5]
\section{First section}
\lipsum[3]
\section*{Section}
\lipsum[4]

\end{document}

Bernard가 상기시킨 것처럼, 대신에 \filcenterpowered by를 사용할 수도 있습니다 .titlesec\centering

sectsty그러나 가능하다면 AboAmmar의 답변처럼 사용하기 쉬울 것입니다 .

답변2

sectsty패키지를 활용한 빠른 솔루션

\documentclass[10pt,a4paper,twoside]{book}
\usepackage[latin1]{inputenc}
\usepackage{lipsum}
%\usepackage{titlesec}
\usepackage{sectsty}

\allsectionsfont{\centering}

\begin{document}
\chapter{The first chapter}
\lipsum[1-5]
\section{First section}
\lipsum[3]
\section*{Section}
\lipsum[4]

\end{document}

또는 간단히 다음과 같이 옵션을 titlesec추가하여 사용하세요 [center].

\documentclass[10pt,a4paper,twoside]{book}
\usepackage[latin1]{inputenc}
\usepackage{lipsum}
\usepackage[center]{titlesec}

\begin{document}
\chapter{The first chapter}
\lipsum[1-5]
\section{First section}
\lipsum[3]
\section*{Section}
\lipsum[4]

\end{document}

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

관련 정보