.png)
Mit dem folgenden Code kann ich ganz einfach die nicht eingefärbte Version meiner \section-Überschrift abrufen:
{\normalfont}
{\filright
\footnotesize
\enspace SECTION \thesection\enspace
}
{8pt}
{\Large\bfseries\sectionfont\filcenter}
Mit diesem Code habe ich fast das gefunden, was ich will
\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}
Obwohl ich fast fertig bin, gibt es zwei Probleme, die über mein aktuelles LaTeX-Fu hinausgehen: Das Fehlen eines Rahmens um den Hauptteil und die nicht zentrierte Natur des Haupttexts. Ich habe eine Vielzahl von \colorbox
und \fcolorbox
Beschwörungsformeln ohne Erfolg ausprobiert, also frage ich mich, ob mir jemand auf tex.stack helfen kann?
Zusammen an einem Ort ist mein 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}
Beim Erstellen des MWE stelle ich fest, dass meine Version nicht so richtig ausgerichtet ist wie die Originalversion. Das kommt zu meinen Problemen noch hinzu …
Antwort1
Hier ist ein Beispiel, wie das geht. Verwenden Sie die explicit
Option im titlesec
Paket und definieren Sie den Titel in einem parbox
. Verwenden Sie ein überlagertes tikz
Bild, um das farbige Feld für den Titel zu zeichnen. Die Höhe der tikz
Zeichnung wurde anhand des gespeicherten Titelfelds plus einem Teil Ihrer bevorzugten Länge berechnet, der sich mit dem Abschnittsbeschriftungsfeld überlappt. Sie können einige der Parameter nach Ihren Wünschen anpassen. Auf diese Weise hat die Sternversion des Abschnittstitels dasselbe Format wie die nummerierte.
\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}