Text Formattingbackground color of lines

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
buergi
Posts: 2
Joined: Fri Mar 18, 2011 11:18 pm

background color of lines

Post by buergi »

Hey,
i'm searching a way to do some advanced line coloring. Specific paragraphs should alternately be colored. I've drawn a rough layout sketch to clarify how it should look like:
book_layout_neut.png
book_layout_neut.png (108.45 KiB) Viewed 2573 times
For the orange flags in the header i used tikz and fancyhdr, which worked very well. But i've some problems with the line coloring. My first idea was something like:

Code: Select all

\documentclass[svgnames]{book}
\usepackage{xcolor}
\usepackage{calc}
\usepackage[dvips]{geometry}
\usepackage{vmargin}

\setpapersize{A5}
\pagecolor{Ivory}
\setmarginsrb{0cm}{1.5cm}{0cm}{1.5cm}{0.5cm}{0.2cm}{1cm}{1cm}
\setlength{\parindent}{0pt}
\pagestyle{plain}

\newcommand{\asays}[1]{\colorbox{Beige}{
    \parbox{\paperwidth}{
        \hangindent=1.5cm \hangafter=0 \parbox{\paperwidth-3cm}{A: #1}}
    }\\}
\newcommand{\bsays}[1]{\colorbox{Bisque}{
    \parbox{\paperwidth}{
        \hangindent=1.5cm \hangafter=0 \parbox{\paperwidth-3cm}{B: #1}}
    }\\}


\begin{document}
\asays {Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt}
\bsays {Lorem ipsum dolor sit amet}
\asays {Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt}
\bsays {Lorem ipsum dolor sit amet}
\end{document}
But unfortunately this causes some problems:
1. Of course the text cannot flow on the text page but only the whole \parbox. This leads to a huge waste of space at the bottom of a page. Paragraphs longer than a page are even cut.
2. The text won't low around graphics (like with wrapfig etc.)

Hopefully someone has an idea how to get the lines colored without those problematic parboxes. If necessary I'd even try to dive a little into TeX but i've no idea where to start.
Thanks a lot in advance,
buergi


Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

buergi
Posts: 2
Joined: Fri Mar 18, 2011 11:18 pm

background color of lines

Post by buergi »

I managed to solve problem 1 by using the framed package

Code: Select all

\documentclass[svgnames]{book}
\usepackage[dvips]{geometry}
\usepackage{framed}
\usepackage{vmargin}
\usepackage{xcolor}
\usepackage{calc}

\setpapersize{A5}
\pagecolor{Ivory}
\setmarginsrb{1.5cm}{1.5cm}{1.5cm}{1.5cm}{0.5cm}{0.2cm}{1cm}{1cm}
\setlength{\parindent}{0pt}
\pagestyle{plain}

\newcommand{\widebox}[2]{\colorbox{#1}{\makebox[\paperwidth]{#2}}}

\newenvironment{shadeda}{%
\def\FrameCommand{\fboxsep=1ex \widebox{Wheat}}%
                  \MakeFramed {\FrameRestore}}%
                 {\endMakeFramed}
\newenvironment{shadedb}{%
\def\FrameCommand{\fboxsep=1ex \widebox{Cornsilk}}%
                  \MakeFramed {\FrameRestore}}%
                 {\endMakeFramed}
\newcommand{\asays} [1]{\begin{shadeda}A: #1\end{shadeda}\vspace{-20pt}}
\newcommand{\bsays} [1]{\begin{shadedb}B: #1\end{shadedb}\vspace{-20pt}}

\begin{document}
\asays {Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt}
\bsays {Lorem ipsum dolor sit amet}
\asays {Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt}
\bsays {Lorem ipsum dolor sit amet}
\end{document}
Problem 1 solved. One problem remaining + one new problem:
2. The text doesn't flow around graphics. wrapfig even breaks the whole text
3. How to get rid of the vertical space between the boxes. The vspace sledgehammer method isn't very satisfying. Especially because the spaces are not equal.

buergi
Post Reply