섹션에서 raisebox를 사용할 때 줄 바꿈

섹션에서 raisebox를 사용할 때 줄 바꿈

NET raisebox에서 명령을 사용할 때 줄바꿈하는 방법 \section내 MWE는 다음과 같습니다.

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{xcolor,lipsum,mdframed}

\definecolor{sectcolor}{cmyk}{0,1,.75,.39}
\definecolor{sectbgcolor}{RGB}{0,106,168}
\definecolor{sectsubbgcolor}{RGB}{0,139,191}

\renewcommand{\thesection}{\thechapter\Alph{section}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}

\makeatletter
\titleformat{\section}
  {\fontsize{18}{20}\selectfont\color{white}\bfseries}
  {\llap{\smash{\parbox[t]{2em}{\raggedleft%
      \colorbox{sectcolor}{%
        \makebox[\dimexpr2em-2\fboxsep\relax][r]{%
          \hfill\strut\thesection
        }%
      }\\[1ex]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    }}\hspace*{0.5em}}%
  }
  {0em}
  {\makebox[\linewidth][l]{\colorbox{sectbgcolor}{\parbox[t]    {\dimexpr\paperwidth-\oddsidemargin-1in-2\fboxsep-5pt\relax}{%
    \strut\fontsize{18}{20}\selectfont\raisebox{-2.5pt}[0pt][0pt]{#1}%
    \if\sectionsubtitle\empty
    \else
      \hspace{5pt}\smash{\colorbox{sectsubbgcolor}    {\strut\large\sectionsubtitle}}%
    \fi}
    }}%
  }

\makeatother

\def\sectionsubtitle{\empty}
\newcommand\Ssection[3][]{%
  \gdef\sectionsubtitle{#3}\section[#1]{#2}\gdef\sectionsubtitle{\empty}%
}

\begin{document}

\chapter{Chapter Title Here}
\section{Count systems}
\lipsum[1]
\Ssection{Number systems}{Consolidating}
\lipsum[1]
\Ssection{Highest common factor and lowest common\hfil\break     multiple}{Consolidating}
\end{document}

답변1

첫째, 제목에 수동 나누기를 추가해서는 안 됩니다. 필요에 따라 여러 줄에 걸쳐 표시되도록 제목 지정 매크로를 설정하는 것이 좋습니다. 귀하의 경우 배경색을 담을 상자를 만들고 parbox텍스트를 담을 상자를 넣으면 됩니다.

둘째, 높이와 깊이가 잘못되었기 때문에 레이즈박스를 사용하고 있다고 생각합니다. 이는 잘못된 사용으로 인해 발생한 것으로 보입니다 \strut. 귀하의 코딩은 \strut\fontszie{...}\selectfont스트럿이 새로운 글꼴 크기로 조정되지 않았음을 의미합니다. 대신 `\fontsize{...}\selectfont\strut' 순서로 작성하세요.

샘플 출력

\documentclass{book}

\usepackage[explicit]{titlesec}
\usepackage{lmodern}
\usepackage[demo]{graphicx}
\usepackage{xcolor,lipsum}

\definecolor{sectcolor}{cmyk}{0,1,.75,.39}
\definecolor{sectbgcolor}{RGB}{0,106,168}
\definecolor{sectsubbgcolor}{RGB}{0,139,191}

\renewcommand{\thesection}{\thechapter\Alph{section}}
\renewcommand{\chaptermark}[1]{\markboth{#1}{}}
\renewcommand{\sectionmark}[1]{\markright{\thesection.\ #1}}

\titleformat{\section}
  {\color{white}\fontsize{18}{20}\bfseries}
  {\llap{\smash{\parbox[t]{2em}{\raggedleft%
      \colorbox{sectcolor}{%
        \makebox[\dimexpr2em-2\fboxsep\relax][r]{%
          \hfill\strut\thesection
        }%
      }\\[1ex]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    \includegraphics[width=1.5em]{image-1}\\[2pt]
    }}\hspace*{0.5em}}%
  }
  {0em}
  {\colorbox{sectbgcolor}{%
  \makebox[\dimexpr\paperwidth-\oddsidemargin-1in-2\fboxsep-5pt\relax]{%
    {\parbox[t]{\linewidth}{%
      \raggedright\fontsize{18}{20}\selectfont\strut #1%
      \if\sectionsubtitle\empty
      \else
      \hspace{5pt}%
      \smash{\colorbox{sectsubbgcolor}{\large\strut\sectionsubtitle}}%
      \fi}}\hfill
      }}%
}

\def\sectionsubtitle{\empty}
\newcommand\Ssection[3][]{%
  \gdef\sectionsubtitle{#3}\section[#1]{#2}\gdef\sectionsubtitle{\empty}%
}

\begin{document}

\chapter{Chapter Title Here}
\section{Count systems}
\lipsum[1]
\Ssection{Number systems}{Consolidating}
\lipsum[1]
\Ssection{Highest common factor and lowest common multiple}{Consolidating}
\end{document}

관련 정보