Here's one approach that uses the titlesec
package for setting the section titles, and TikZ for drawing the bar. The section numbers are placed in a TikZ node that will grow automatically to accommodate the numbers:
\documentclass{book}
\usepackage{titlesec}
\usepackage{lipsum}
\usepackage{tikz}\usetikzlibrary{shapes.misc}
\newcommand\titlebar{%
\tikz[baseline,trim left=3.1cm,trim right=3cm] {
\fill [cyan!25] (2.5cm,-1ex) rectangle (\textwidth+3.1cm,2.5ex);
\node [
fill=cyan!60!white,
anchor= base east,
rounded rectangle,
minimum height=3.5ex] at (3cm,0) {
\textbf{\arabic{chapter}.\thesection.}
};
}%
}
\titleformat{\section}{\large}{\titlebar}{0.1cm}{}
\renewcommand*{\thesection}{\arabic{section}}
\begin{document}
\chapter{First Chapter}
\section{Section name}
\lipsum[1]
\setcounter{chapter}{9999}
\setcounter{section}{105}
\section{Section name}
\lipsum[1-2]
\end{document}
Certain commands do not permit new paragraphs: \textbf
, \textsf
, \texttt
, etc. To achieve the effect you want, you'll need to use a different form: \bfseries
, \sffamily
, \ttfamily
, \itshape
. If you load the xcolor
package, then you can issue \color{<name_of_color>}
.
If you don't want to effect document wide changes, then you need to embed these commands within some kind of grouping. That can be as simple as {...}
or an environment like \begin{minipage}{<width>}...\end{minipage}
.
Here's a MWE:
\documentclass{article}
\usepackage{xcolor}
\usepackage{lipsum}
\begin{document}
{\bfseries \lipsum[1-2] }
{\sffamily \lipsum[1-2] }
{\itshape \lipsum[1-2] }
{\color{blue} \lipsum[1-2] }
\begin{itemize}\bfseries\itshape\color{orange}
\item A
\item B
\item C
\end{itemize}
\lipsum[1]
\end{document}
If you don't want to hassle with embedding things inside another environment or parentheses, then you can use \normalfont
to restore settings. This won't, however, work for restoring color; for that you'll have to issue \normalcolor
or \color{black}
.
\lipsum[1]
\color{green}\itshape
\lipsum[1]
\color{black}\normalfont
\lipsum[1]
In a similar fashion, you can change font sizes by issuing \large
or \scriptsize
etc., to undo the effect of these commands (if not embedded in some kind of a group) use \normalsize
.
In summary
Each font changing command is paired with a command which can work across multiple paragraphs.
\textbf{...} \bfseries
\textsf{...} \sffamily
\textit{...} \itshape
etc.
These are all well documented; so it shouldn't be hard for you to find all such paired commands. However, a word of caution, do not use \bf
, \it
, and the such. These are TeX commands and most likely will not do what you want. The LaTeX commands \bfseries
, \itshape
, only change the aspect of the text you want (series type, shape, family). Among more subtle effects the LaTeX commands enact and depending on whether the fonts you use provide support, the effects of the LaTeX commands are additive.
If the commands in the second column are not embedded within some kind of a group and you want to restore default behavior, then you can issue
\normalfont
You can change the size of the font with the commands
\large
\small
\footnotesize
The default size can be restored using
\normalsize
Color attributes can be changed, provided you've loaded xcolor
. As with \textxx{...}
type commands, there is also a pair:
\textcolor{<color>}{<text>} \color{<color>}
Colors can be restored by issuing
\normalcolor
Best Answer
You can use the
titlesec
package to customize the formatting for the sectional unit headings; themdframed
or theframed
packages give you the possibility to get framed text; a little example:I wasn't sure about the desired width for the frame, so here's another option: