섹션 하나만 맞춤설정하세요.

섹션 하나만 맞춤설정하세요.

나는 이미 이 질문을 했지만 답변을 받지 못했습니다. 해결책을 찾으려고 노력했지만 여전히 문제가 있습니다.

모든 섹션이 특정 스타일로 표시되고 한 섹션만 다른 스타일로 표시되는 문서를 만들고 싶습니다. 이를 위해 섹션의 두 가지 스타일을 구현했지만 문제는 이를 동일한 문서에 넣기 위해 도착하지 않는다는 것입니다.

다음은 다른 스타일로 나타나는 내 섹션의 코드입니다(섹션 2).

\documentclass{book}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\definecolor{myBlue}{HTML}{0088FF}
\begin{document}
    \chapter{CHAP 1}
    \section{Section one}
    \titleformat{\section}[hang]{\Large\bfseries\sffamily\fontfamily{pag}\selectfont}%
    {\rlap{\color{myBlue}\rule[-6pt]{\textwidth}{1.2pt}}\colorbox{myBlue}{%
            \raisebox{0pt}[13pt][3pt]{ \makebox[70pt]{% height, width
                    \fontfamily{pag}\selectfont\color{white}{\thesection}}
    }}}%
    {15pt}%
    { \color{myBlue}#1
        %
    }
    \section{Section two}
    \lipsum[2]
    \lipsum[1]
    \titleformat{\section}[block]
    {\normalfont\large\bfseries}
    {\thesection}
    {1em}{#1}
    {}
    \section{Section three}
    \section{Section four}
\end{document} 

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

섹션 1, 3, 4에는 다음 코드를 사용하고 싶습니다.

\renewcommand{\section}{\@startsection{section}{1}{\z@}
{-12pt \@plus -1ex \@minus -.4ex}
{2ex \@plus.2ex }
{\normalfont\fontsize{14pt}{16pt}\fontfamily{pag}\bfseries\color{myBlue}}}

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

최종 결과가 다음 그림과 같기를 바랍니다.

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

답변1

\setupnormalsections섹션 제목의 형식을 변경하는 데 사용되는 명령(이름 및 \setupspecialsections여기) 을 만들고 \titleformat문서 중간에서 이러한 명령을 호출할 수 있습니다.

매크로가 확장될 때 ##삽입되도록 하려면 매크로 정의에서 사용해야 한다는 점을 잊지 마십시오 . #통과하려면 이게 필요해#1 있는 그대로의 다섯 번째 필수 인수에서 \titleformat. 두 개가 없으면 #매크로 대체 텍스트가 읽힐 때마다 #1매크로를 확장하면 이를 #1매크로의 첫 번째 인수로 대체합니다. 첫째, 여기서는 이것이 바람직하지 않습니다. 둘째, 여기서 문제의 매크로는 \setupnormalsections및 입니다 \setupspecialsections. 그들은 아무런 논쟁도 하지 않습니다.

\documentclass{book}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage[explicit]{titlesec}
\definecolor{myBlue}{HTML}{0088FF}

\makeatletter

\newcommand*{\setupnormalsections}{%
  \titleformat{\section}[block]
    {\normalfont\fontsize{14pt}{16pt}\fontfamily{pag}\bfseries\color{myBlue}}
    {\thesection}
    {1em}{##1}
    {}%
}

\newcommand*{\setupspecialsections}{%
  \titleformat{\section}[hang]
    {\Large\bfseries\sffamily\fontfamily{pag}\selectfont}%
    {\rlap{\color{myBlue}\rule[-6pt]{\textwidth}{1.2pt}}\colorbox{myBlue}{%
      \raisebox{0pt}[13pt][3pt]{\makebox[70pt]{% height, width
          \fontfamily{pag}\selectfont\color{white}{\thesection}}%
      }}}%
    {15pt}%
    {\color{myBlue}##1}%
}

\makeatother

\setupnormalsections

\begin{document}

    \chapter{CHAP 1}
    \section{Section one}

    \setupspecialsections
    \section{Section two}

    \lipsum[2]
    \lipsum[1]

    \setupnormalsections
    \section{Section three}
    \section{Section four}

\end{document}

스크린샷

관련 정보