PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : farbige, umrahmte titel mit zeilenumbruch



don_shifty
17-08-2010, 14:23
hallo liebes forum

vorgabe ist, die titel zentriert und in farbigen boxen zu haben...
folgendes hab ich gemacht:



\documentclass[10pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{color}
\usepackage[english]{babel}
\usepackage[nobottomtitles*, explicit]{titlesec} %formatiert Titel und abstände
\titleformat{\part}[block]{\sffamily}{}{0pt}{\Large \centering \usefont{T1}{cmss}{bx}{n}\selectfont \colorbox{Orange}{%
\textcolor{Periwinkle}{Part \thepart \\ \Huge#1}}}
\titleformat{\section}[block]{\sffamily}{}{0pt}{\Large \centering \usefont{T1}{cmss}{bx}{n}\selectfont \colorbox{Gray}{%
\textcolor{White}{Section \thesection \newline #1}}}
\begin{document}
\part{The First Part}
\section{the first section}
\subsection{the first subsection}
\blindtext
\end{document}


probleme:
1. mit dem rot markierten \centering gibts mir folgenden error: ! LaTeX Error: Something's wrong--perhaps a missing \item.
aber ohne dieses \centering ist (wie soll es auch ander sein) der titel nicht zentriert <=> vorgabe!

2. die orange markierten zeilenumbruch-befehle funktionieren nicht. was ich gerne hätte wäre:
---
part I *zeilenumbruch*
Name_des_ersten_Parts
---
dasselbe mit den sections

was mache ich falsch?
danke für die hilfe!
mfg shifty

u_fischer
17-08-2010, 14:40
Eine \colorbox kann nicht mehrere Zeilen enthalten. Du musst also noch ein \parbox oder eine Tabelle einfügen:


\documentclass[10pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[T1]{fontenc}
\usepackage[usenames,dvipsnames]{color}
\usepackage[english]{babel}
\usepackage[nobottomtitles*, explicit]{titlesec} %formatiert Titel und abstände
\titleformat{\part}[block]
{\sffamily}{}{0pt}
{\Large \usefont{T1}{cmss}{bx}{n}\selectfont\filcenter %
\colorbox{Orange}{\color{Periwinkle}%
\begin{tabular}{c}Part \thepart \\ \Huge#1\end{tabular}}%
}
%\titleformat{\section}[block]{\sffamily}{}{0pt}{\Large \centering \usefont% {T1}{cmss}{bx}{n}\selectfont \colorbox{Gray}{%
% \textcolor{White}{Section \thesection \newline #1}}}
\begin{document}
\part{The First Part}
\section{the first section}
\subsection{the first subsection}
\blindtext
\end{document}

don_shifty
17-08-2010, 15:49
cool, scheint zu funktionnieren! danke ulrike!

würde trotzdem noch gerne wissen, wieso der \centering command eine fehlermeldung provozierte...

mfg shifty

u_fischer
17-08-2010, 16:17
\centering definiert \\ um. Damit ist der \\ in der Box nicht mehr einfach nur wirkungslos sondern ergibt einen Fehler.