Using color in varwidth environment produces warning and does not work as intended
up vote
3
down vote
favorite
Trying to use color in a varwidth
environment, I stumbled upon
a warning from the varwidth
package. Inspecting the issue and
trying the same with parbox
and the minipage
environment lead
to the following MWE:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
% color{red}
test
}abc &
begin{minipage}[t]{4em}
% color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
% color{red}
test
end{varwidth}
abc\
% but using color needs leavevmode and breaks varwidth
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
% throws error (twice):
% Package varwidth Warning: Failed to reprocess entire contents on input line 45.
begin{varwidth}[t]{4em}
leavevmodecolor{red}
test
end{varwidth}% this is line 45
abc
end{tabular}
end{document}
produces the following warning twice
Package varwidth Warning: Failed to reprocess entire contents on input line 45.
As you can see, you can use color
within parbox
es and minipage
s,
if you insert a leavevmode
, but it breaks the varwidth
environment
with a warning. The behavior is similar to a parbox
without leavevmode
.
Is this (easily) fixable? Are there alternatives to varwidth
?
To clarify what I want: I want to use colors in a varwidth
environment
that work as intended: placement as in the line without colors.
errors warnings varwidth
add a comment |
up vote
3
down vote
favorite
Trying to use color in a varwidth
environment, I stumbled upon
a warning from the varwidth
package. Inspecting the issue and
trying the same with parbox
and the minipage
environment lead
to the following MWE:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
% color{red}
test
}abc &
begin{minipage}[t]{4em}
% color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
% color{red}
test
end{varwidth}
abc\
% but using color needs leavevmode and breaks varwidth
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
% throws error (twice):
% Package varwidth Warning: Failed to reprocess entire contents on input line 45.
begin{varwidth}[t]{4em}
leavevmodecolor{red}
test
end{varwidth}% this is line 45
abc
end{tabular}
end{document}
produces the following warning twice
Package varwidth Warning: Failed to reprocess entire contents on input line 45.
As you can see, you can use color
within parbox
es and minipage
s,
if you insert a leavevmode
, but it breaks the varwidth
environment
with a warning. The behavior is similar to a parbox
without leavevmode
.
Is this (easily) fixable? Are there alternatives to varwidth
?
To clarify what I want: I want to use colors in a varwidth
environment
that work as intended: placement as in the line without colors.
errors warnings varwidth
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once usingletcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)
– John Kormylo
Nov 17 at 19:07
add a comment |
up vote
3
down vote
favorite
up vote
3
down vote
favorite
Trying to use color in a varwidth
environment, I stumbled upon
a warning from the varwidth
package. Inspecting the issue and
trying the same with parbox
and the minipage
environment lead
to the following MWE:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
% color{red}
test
}abc &
begin{minipage}[t]{4em}
% color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
% color{red}
test
end{varwidth}
abc\
% but using color needs leavevmode and breaks varwidth
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
% throws error (twice):
% Package varwidth Warning: Failed to reprocess entire contents on input line 45.
begin{varwidth}[t]{4em}
leavevmodecolor{red}
test
end{varwidth}% this is line 45
abc
end{tabular}
end{document}
produces the following warning twice
Package varwidth Warning: Failed to reprocess entire contents on input line 45.
As you can see, you can use color
within parbox
es and minipage
s,
if you insert a leavevmode
, but it breaks the varwidth
environment
with a warning. The behavior is similar to a parbox
without leavevmode
.
Is this (easily) fixable? Are there alternatives to varwidth
?
To clarify what I want: I want to use colors in a varwidth
environment
that work as intended: placement as in the line without colors.
errors warnings varwidth
Trying to use color in a varwidth
environment, I stumbled upon
a warning from the varwidth
package. Inspecting the issue and
trying the same with parbox
and the minipage
environment lead
to the following MWE:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
% color{red}
test
}abc &
begin{minipage}[t]{4em}
% color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
% color{red}
test
end{varwidth}
abc\
% but using color needs leavevmode and breaks varwidth
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
% throws error (twice):
% Package varwidth Warning: Failed to reprocess entire contents on input line 45.
begin{varwidth}[t]{4em}
leavevmodecolor{red}
test
end{varwidth}% this is line 45
abc
end{tabular}
end{document}
produces the following warning twice
Package varwidth Warning: Failed to reprocess entire contents on input line 45.
As you can see, you can use color
within parbox
es and minipage
s,
if you insert a leavevmode
, but it breaks the varwidth
environment
with a warning. The behavior is similar to a parbox
without leavevmode
.
Is this (easily) fixable? Are there alternatives to varwidth
?
To clarify what I want: I want to use colors in a varwidth
environment
that work as intended: placement as in the line without colors.
errors warnings varwidth
errors warnings varwidth
asked Nov 17 at 19:01
nox
3,365421
3,365421
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once usingletcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)
– John Kormylo
Nov 17 at 19:07
add a comment |
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once usingletcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)
– John Kormylo
Nov 17 at 19:07
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once using
letcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)– John Kormylo
Nov 17 at 19:07
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once using
letcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)– John Kormylo
Nov 17 at 19:07
add a comment |
2 Answers
2
active
oldest
votes
up vote
2
down vote
You could use textcolor
:
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
or an additional group:
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
Example:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
parbox[t]{4em}{
test
}abc &
begin{minipage}[t]{4em}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
test
end{varwidth}
abc\
parbox[t]{4em}{
textcolor{red}{test}
}abc &
begin{minipage}[t]{4em}
textcolor{red}{test}
end{minipage}
abc &
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
abc
\
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
abc
end{tabular}
end{document}
Result:
add a comment |
up vote
1
down vote
Starting a minipage
or parbox
with color
always has the side effect of producing a blank line at the top. You can solve the issue by using
begin{minipage}[t]{4em}
leavevmodecolor{red}% <--- don't forget
test
end{minipage}
However this doesn't work for varwidth
. You can instead start the coloring outside the varwidth
environment:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
newenvironment{colorvarwidth}[1]
{leavevmodecolor{#1}varwidth}
{endvarwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
leavevmodecolor{red}%
test
}abc &
begin{minipage}[t]{4em}
leavevmodecolor{red}%
test
end{minipage}
abc &
begin{colorvarwidth}{red}[t]{4em}
test
end{colorvarwidth}
abc
end{tabular}
end{document}
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
You could use textcolor
:
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
or an additional group:
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
Example:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
parbox[t]{4em}{
test
}abc &
begin{minipage}[t]{4em}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
test
end{varwidth}
abc\
parbox[t]{4em}{
textcolor{red}{test}
}abc &
begin{minipage}[t]{4em}
textcolor{red}{test}
end{minipage}
abc &
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
abc
\
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
abc
end{tabular}
end{document}
Result:
add a comment |
up vote
2
down vote
You could use textcolor
:
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
or an additional group:
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
Example:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
parbox[t]{4em}{
test
}abc &
begin{minipage}[t]{4em}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
test
end{varwidth}
abc\
parbox[t]{4em}{
textcolor{red}{test}
}abc &
begin{minipage}[t]{4em}
textcolor{red}{test}
end{minipage}
abc &
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
abc
\
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
abc
end{tabular}
end{document}
Result:
add a comment |
up vote
2
down vote
up vote
2
down vote
You could use textcolor
:
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
or an additional group:
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
Example:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
parbox[t]{4em}{
test
}abc &
begin{minipage}[t]{4em}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
test
end{varwidth}
abc\
parbox[t]{4em}{
textcolor{red}{test}
}abc &
begin{minipage}[t]{4em}
textcolor{red}{test}
end{minipage}
abc &
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
abc
\
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
abc
end{tabular}
end{document}
Result:
You could use textcolor
:
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
or an additional group:
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
Example:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
parbox[t]{4em}{
test
}abc &
begin{minipage}[t]{4em}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
test
end{varwidth}
abc\
parbox[t]{4em}{
textcolor{red}{test}
}abc &
begin{minipage}[t]{4em}
textcolor{red}{test}
end{minipage}
abc &
begin{varwidth}[t]{4em}
textcolor{red}{test}
end{varwidth}
abc
\
parbox[t]{4em}{
leavevmode
color{red}
test
}abc &
begin{minipage}[t]{4em}
leavevmode
color{red}
test
end{minipage}
abc &
begin{varwidth}[t]{4em}
leavevmode
{color{red}
test}
end{varwidth}
abc
end{tabular}
end{document}
Result:
edited 2 days ago
answered Nov 17 at 23:34
esdd
57.6k34485
57.6k34485
add a comment |
add a comment |
up vote
1
down vote
Starting a minipage
or parbox
with color
always has the side effect of producing a blank line at the top. You can solve the issue by using
begin{minipage}[t]{4em}
leavevmodecolor{red}% <--- don't forget
test
end{minipage}
However this doesn't work for varwidth
. You can instead start the coloring outside the varwidth
environment:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
newenvironment{colorvarwidth}[1]
{leavevmodecolor{#1}varwidth}
{endvarwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
leavevmodecolor{red}%
test
}abc &
begin{minipage}[t]{4em}
leavevmodecolor{red}%
test
end{minipage}
abc &
begin{colorvarwidth}{red}[t]{4em}
test
end{colorvarwidth}
abc
end{tabular}
end{document}
add a comment |
up vote
1
down vote
Starting a minipage
or parbox
with color
always has the side effect of producing a blank line at the top. You can solve the issue by using
begin{minipage}[t]{4em}
leavevmodecolor{red}% <--- don't forget
test
end{minipage}
However this doesn't work for varwidth
. You can instead start the coloring outside the varwidth
environment:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
newenvironment{colorvarwidth}[1]
{leavevmodecolor{#1}varwidth}
{endvarwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
leavevmodecolor{red}%
test
}abc &
begin{minipage}[t]{4em}
leavevmodecolor{red}%
test
end{minipage}
abc &
begin{colorvarwidth}{red}[t]{4em}
test
end{colorvarwidth}
abc
end{tabular}
end{document}
add a comment |
up vote
1
down vote
up vote
1
down vote
Starting a minipage
or parbox
with color
always has the side effect of producing a blank line at the top. You can solve the issue by using
begin{minipage}[t]{4em}
leavevmodecolor{red}% <--- don't forget
test
end{minipage}
However this doesn't work for varwidth
. You can instead start the coloring outside the varwidth
environment:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
newenvironment{colorvarwidth}[1]
{leavevmodecolor{#1}varwidth}
{endvarwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
leavevmodecolor{red}%
test
}abc &
begin{minipage}[t]{4em}
leavevmodecolor{red}%
test
end{minipage}
abc &
begin{colorvarwidth}{red}[t]{4em}
test
end{colorvarwidth}
abc
end{tabular}
end{document}
Starting a minipage
or parbox
with color
always has the side effect of producing a blank line at the top. You can solve the issue by using
begin{minipage}[t]{4em}
leavevmodecolor{red}% <--- don't forget
test
end{minipage}
However this doesn't work for varwidth
. You can instead start the coloring outside the varwidth
environment:
documentclass{article}
usepackage{xcolor}
usepackage{varwidth}
newenvironment{colorvarwidth}[1]
{leavevmodecolor{#1}varwidth}
{endvarwidth}
begin{document}
begin{tabular}{lll}
verb|parbox| & verb|minipage| & verb|varwidth| \
%without color, everything works as expected.
parbox[t]{4em}{
leavevmodecolor{red}%
test
}abc &
begin{minipage}[t]{4em}
leavevmodecolor{red}%
test
end{minipage}
abc &
begin{colorvarwidth}{red}[t]{4em}
test
end{colorvarwidth}
abc
end{tabular}
end{document}
answered Nov 17 at 23:48
egreg
698k8518573126
698k8518573126
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460489%2fusing-color-in-varwidth-environment-produces-warning-and-does-not-work-as-inten%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
As Henny Youngman used to say, don't do that. You could always run the data twice (environ package), once using
letcolor=@gobble
and varwidth and save the width, then again using parbox using the computed width. (Actually, I think that is sort of how varwidth works.)– John Kormylo
Nov 17 at 19:07