セクションで raisebox を使用する場合の改行

セクションで raisebox を使用する場合の改行

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内部にテキストを保持するボックスを配置することで、これを実現できます。

次に、高さと深さが間違っているため、raisebox を使用していると思います。これは、間違った を使用しているために発生したようです\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}

関連情報