프레임 모드의 배경색(titlesec)

프레임 모드의 배경색(titlesec)

다음 코드를 사용하면 \section 헤더의 색상이 지정되지 않은 버전을 쉽게 얻을 수 있습니다.

{\normalfont}
{\filright
    \footnotesize
    \enspace SECTION \thesection\enspace
}
{8pt}
{\Large\bfseries\sectionfont\filcenter}

다음과 같이 보일 것입니다: 무색 \섹션 헤더

이 코드로 내가 원하는 것을 거의 얻었습니다.

\titleformat{\section}
{\LARGE}
{\rlap
    {\color{Fraoch!30}
        \rule[-0.4cm]{\linewidth}{1.2cm}
    }
    {\normalfont}
    {\filright
        \raisebox{1em}{
            \fcolorbox{black}{white}{
                    \footnotesize
                    \enspace SECTION \thesection\enspace
                }
        }
    }
}
{1em}
{\Large\sectionfont\filcenter}

다음과 같습니다. 컬러 \섹션 헤더

가까운 동안 현재 LaTeX-Fu 외에 두 가지 문제가 있습니다. 주요 부분 주변에 테두리가 없고 본문이 중앙에 위치하지 않습니다. 다양한 주문을 시도했지만 \colorbox\fcolorbox이 없었는데 tex.stack에 도움을 줄 수 있는 사람이 있는지 궁금합니다.

내 MWE가 한 곳에 모였습니다.

\documentclass{article}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage[table,x11names]{xcolor}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{xparse}
\usepackage{imakeidx}
\usepackage{bbding}
\usepackage{titlesec}
\usepackage[hyperindex]{hyperref}

\defaultfontfeatures{Ligatures=TeX}
%% \setmainfont{Hoefler Text}

\newcounter{cnt}
\setcounter{cnt}{0}

\NewDocumentCommand{\voc}{ m O{\O} O{#1}} {%
    \stepcounter{cnt}%
    \index[english]{#2|textit}
    \index{#3}%
    #1 & #2\\%
}
\newfontfamily\sectionfont{Goudy Bookletter 1911}
\definecolor{Fraoch}{named}{LightPink4}

\begin{document}
\titleformat{\section}[frame]
{\normalfont}
{\filright
    \footnotesize
    \enspace SECTION \thesection\enspace
}
{8pt}
{\Large\bfseries\sectionfont\filcenter}

{\setcounter{section}{9}
\section{UNIT 1 OF 9, English Translations}
\subsection{Intro}
\begin{tabular}{lr}
    \toprule
    \rowcolor{Fraoch!40}
    Gaelic & English\\
    \midrule
    \voc{Anna}[female name]
    \voc{Calum}[male name]
    \voc{Eilidh}[female name]
    \bottomrule
\end{tabular}
\titleformat{\section}
{\LARGE}
{\rlap
    {\color{Fraoch!30}
        \rule[-0.4cm]{\linewidth}{1.2cm}
    }
    {\normalfont}
    {\filright
        \raisebox{1em}{
            \fcolorbox{black}{white}{
                    \footnotesize
                    \enspace SECTION \thesection\enspace
                }
        }
    }
}
{1em}
{\Large\sectionfont\filcenter}
{\setcounter{section}{9}
\section{UNIT 1 OF 9, English Translations}
\subsection{Intro}
\begin{tabular}{lr}
    \toprule
    \rowcolor{Fraoch!40}
    Gaelic & English\\
    \midrule
    \voc{Anna}[female name]
    \voc{Calum}[male name]
    \voc{Eilidh}[female name]
    \bottomrule
\end{tabular}

\end {document}

MWE를 제작할 때 내 버전이 원본 버전처럼 제대로 정렬되지 않았다는 점에 주목했습니다. 내 문제에 추가 ...

답변1

다음은 이를 수행하는 방법의 예입니다. 패키지 explicit의 옵션을 사용 titlesec하고 parbox. 오버레이된 tikz그림을 사용하여 제목에 대한 색상 상자를 그립니다. 도면 의 높이는 tikz저장된 제목 상자에 섹션 레이블 상자와 겹치는 원하는 길이의 일부를 더하여 계산되었습니다. 일부 매개변수를 원하는 대로 조정할 수 있습니다. 이런 방식으로 섹션 제목의 별표 버전은 번호가 매겨진 제목과 동일한 형식을 갖게 됩니다.

\documentclass{article}
\usepackage{fontspec}
\usepackage{lipsum}
\usepackage{enumitem}
\usepackage[table,x11names]{xcolor}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{xparse}
\usepackage{imakeidx}
\usepackage{bbding}
\usepackage[explicit]{titlesec}
\usepackage[hyperindex]{hyperref}
\defaultfontfeatures{Ligatures=TeX}
%% \setmainfont{Hoefler Text}

\newcounter{cnt}
\setcounter{cnt}{0}

\NewDocumentCommand{\voc}{ m O{\O} O{#1}} {%
    \stepcounter{cnt}%
    \index[english]{#2|textit}
    \index{#3}%
    #1 & #2\\%
}
\newfontfamily\sectionfont{Goudy Bookletter 1911}
\definecolor{Fraoch}{named}{LightPink4}
\usepackage{tikz}
\usepackage{calc}
\titleformat{\section}[display]
{\footnotesize}
{%
\fcolorbox{black}{white}{%
\enspace SECTION \thesection\enspace}%
}
{2pt}
{%
\sbox0{\parbox{\textwidth}{\Large\sectionfont\filcenter#1}}%
\tikz[remember picture,overlay,blend mode=overlay]
{\draw[fill=Fraoch!40] (0.5\pgflinewidth,-\dp0-5pt) rectangle (\textwidth-0.5\pgflinewidth,\ht0+5pt);}%
\parbox{\textwidth}{\Large\sectionfont\filcenter#1}%
}
\begin{document}
\setcounter{section}{9}
\section{UNIT 1 OF 9, English Translations}
\subsection{Intro}
\begin{tabular}{lr}
    \toprule
    \rowcolor{Fraoch!40}
    Gaelic & English\\
    \midrule
    \voc{Anna}[female name]
    \voc{Calum}[male name]
    \voc{Eilidh}[female name]
    \bottomrule
\end{tabular}
\section{Example of a super super super super super super super super super long title}
\lipsum[1]
\section*{Example of a super super super super super super super super super long title without number}
\end {document}

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

관련 정보