Discussion:
package framed, shaded environment can not keep the color when page break occurs
(too old to reply)
Jinsong Zhao
2017-09-22 05:49:54 UTC
Hi there,

The minimal example is below. when page break occurs in an alltt
environment, the color is different on the two pages. How to fix it?

Best,
Jinsong

\documentclass{article}

\usepackage{color}
\definecolor{hlstr}{rgb}{0.192,0.494,0.8}

\usepackage{framed}
\usepackage{alltt}

\begin{document}

In the following example, color is different in the two pages. If you
typeset
all the contents in one page, the color is same. \vskip 400pt

\color{hlstr}
\begin{alltt}
textConnection
con,temp,times,content
31,a,I,B
54,b,I,A
38,c,I,C
53,a,II,A
49,b,II,C
42,c,II,B
57,a,III,C
62,b,III,B
64,c,III,A
\end{alltt}

\end{document}
jfbu
2017-09-22 07:40:46 UTC
Post by Jinsong Zhao
Hi there,
The minimal example is below. when page break occurs in an alltt environment, the color is different on the two pages. How to fix it?
Best,
Jinsong
\documentclass{article}
\usepackage{color}
\definecolor{hlstr}{rgb}{0.192,0.494,0.8}
\usepackage{framed}
\usepackage{alltt}
\begin{document}
In the following example, color is different in the two pages. If you typeset
all the contents in one page, the color is same. \vskip 400pt
\color{hlstr}
\begin{alltt}
textConnection
con,temp,times,content
31,a,I,B
54,b,I,A
38,c,I,C
53,a,II,A
49,b,II,C
42,c,II,B
57,a,III,C
62,b,III,B
64,c,III,A
\end{alltt}
\end{document}
Hi Jinsong

try

\begingroup
\color{hlstr}
\begin{alltt}
textConnection
con,temp,times,content
31,a,I,B
54,b,I,A
38,c,I,C
53,a,II,A
49,b,II,C
42,c,II,B
57,a,III,C
62,b,III,B
64,c,III,A
\end{alltt}
\endgroup

Jean-François
Ulrike Fischer
2017-09-22 08:01:11 UTC
Post by Jinsong Zhao
Hi there,
The minimal example is below. when page break occurs in an alltt
environment, the color is different on the two pages. How to fix it?
This is rather difficult (and not related to alltt). When the
complete text of your box should have this color you can use the
code of Jean-François (jfbu).

Or e.g.

\usepackage[many]{tcolorbox} and then
\begin{tcolorbox}[breakable,coltext=hlstr]

But if there should be also black text in the box, then you have a
problem as color commands often don't survive when a box is broken,
see e.g.
https://tex.stackexchange.com/questions/150780/color-bleeding-when-using-vsplit-for-a-box-with-colored-text

An alternative here is to use lualatex where you can color the font,
this would work.

https://tex.stackexchange.com/questions/220118/maintaining-text-colour-change-in-a-breakable-tcolorbox
--
Ulrike Fischer
http://www.troubleshooting-tex.de/