.png)
Es fácil obtener la versión sin color de mi encabezado \section usando el siguiente código:
{\normalfont}
{\filright
\footnotesize
\enspace SECTION \thesection\enspace
}
{8pt}
{\Large\bfseries\sectionfont\filcenter}
Casi tengo lo que quiero con este código.
\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}
Si bien está cerca, hay dos problemas más allá de mi LaTeX-Fu actual; La falta de un borde alrededor de la parte principal y la naturaleza descentrada del texto principal. Probé una variedad de \colorbox
encantamientos \fcolorbox
sin suerte, así que me pregunto si alguien en tex.stack puede echarme una mano.
Juntos en un solo lugar está mi 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}
Al elaborar el MWE observo que mi versión no está alineada correctamente como lo está la versión original. Añade eso a mis problemas...
Respuesta1
Aquí tienes un ejemplo de cómo hacerlo. Utilice la explicit
opción en el titlesec
paquete y defina el título en un archivo parbox
. Usando una tikz
imagen superpuesta para dibujar el cuadro de color del título. La altura del tikz
dibujo se calculó utilizando el cuadro guardado del título más algo de su longitud preferida, que se superpondrá con el cuadro de etiqueta de la sección. Puede ajustar algunos de los parámetros según sus preferencias. De esta forma, la versión estrella del título de la sección tendrá el mismo formato que la numerada.
\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}