페이지 외부의 섹션 번호

페이지 외부의 섹션 번호

내 질문에 이어섹션 제목 사용자 정의, 섹션 번호가 항상 페이지 바깥쪽에 있는 상자를 갖고 싶습니다(저는 양면 옵션을 사용하고 있습니다). 즉, 홀수 페이지의 경우 섹션 번호가 있는 상자가 오른쪽에 있어야 하고, 짝수 페이지의 경우 섹션 번호가 있는 상자가 왼쪽에 있어야 합니다.

짝수 페이지의 경우:

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

홀수 페이지의 경우:

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

문제는 다음과 같습니다.

  1. 스니펫의 원하는 위치에 섹션 번호를 가져오기 위해 코드를 수동으로 변경했습니다. 그러나 물론 이는 큰 문서에는 허용되지 않습니다. 이 작업을 자동으로 수행하는 데 도움이 되나요?
  2. 홀수 페이지의 경우 짝수 페이지처럼 텍스트 영역 외부에 상자를 가져올 수 없었습니다.

다시 한 번 어떤 안내도 환영합니다.

내 MWE는 다음과 같습니다.

\documentclass[openright]{scrbook}
\usepackage{geometry}
\geometry{a4paper,twoside, margin=3cm}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{xhfill}

\renewcommand*{\sectionformat}{%
    \usekomafont{section}%
    \makebox[0pt][r]{%
    \fboxrule=1.5pt\fcolorbox{blue}{white!0}{\color{black}\thesection}\color{blue}\rule[.6ex]{10pt}{1.5pt}
    }%
}
\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
    \@hangfrom{\hskip #2#3}{\color{blue}#4}$\;$%
    \xrfill[.6ex]{1.5pt}[blue]%
}
\makeatother

\begin{document}
    \chapter{Introduction}
    \section{Section 1}
    \Blindtext[2]
    \section{Section 2}
    \Blindtext[2]
    \section{Section 3}
    \Blindtext[2]
    \section{Section 4}
    \Blindtext[2]
\end{document}

감사해요!

답변1

KOMA-Script 명령을 사용할 수 있습니다 \Ifthispageodd.

\documentclass[twoside,open=right]{scrbook}
\usepackage{geometry}
\geometry{margin=3cm}
\usepackage{blindtext}% only for dummy text
\usepackage{xcolor}
\usepackage{xhfill}

\renewcommand*{\sectionformat}{%
  \fboxrule=1.5pt\fcolorbox{.}{white}{\normalcolor\thesection}%
}
\renewcommand*{\subsectionformat}{%
  \fboxrule=1.5pt\fcolorbox{.}{white}{\normalcolor\thesubsection}%
}

\makeatletter
\renewcommand*{\sectionlinesformat}[4]{%
  \Ifthispageodd
    {\rule[.6ex]{10pt}{1.5pt}\;#4\;\xrfill[.6ex]{1.5pt}[.]\hspace{-1pt}\usekomafont{#1}\makebox[0pt][l]{\rule[.6ex]{11pt}{1.5pt}#3}}
    {\makebox[0pt][r]{#3\rule[.6ex]{10pt}{1.5pt}\;}#4\;\xrfill[.6ex]{1.5pt}[.]}%
}
\makeatother

\addtokomafont{section}{\color{blue!50!black}}
\addtokomafont{subsection}{\color{green!50!black}}

\begin{document}
\chapter{Introduction}
\section{Section 1}
\subsection{Subsection}
\Blindtext[2]
%\vspace{4\baselineskip}
\section{Section 2}
\Blindtext[1]
%\clearpage
\section{Section 3}
\Blindtext[2]
\section{Section 4, very long section title that requires more than one line}
\Blindtext[2]
\end{document}

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

경고: \Ifthispageodd제한이 있습니다. 한 페이지에서 명령을 실행했는데 내용이 다음 페이지로 이동하면 잘못된 것입니다. \vspace{4\baselineskip}문제를 보려면 해당 행의 주석 처리를 제거하십시오 . 따라서 작업을 마친 후 문서를 제어하고 예를 들어 문제를 해결해야 합니다. \clearpage.


추가 비고: 질문의 코드는 섹션, 하위 섹션 및 하위 하위 섹션 제목에 동일한 형식을 사용합니다. 이 동작과 섹션 및 하위 섹션 제목에 다른 색상을 사용하는 방법을 보여주기 위해 하위 섹션을 추가했습니다.

관련 정보