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}


MWE result



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 parboxes and minipages,
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.










share|improve this question






















  • 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















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}


MWE result



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 parboxes and minipages,
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.










share|improve this question






















  • 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













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}


MWE result



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 parboxes and minipages,
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.










share|improve this question













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}


MWE result



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 parboxes and minipages,
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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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
















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










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:



enter image description here






share|improve this answer






























    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}


    enter image description here






    share|improve this answer





















      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "85"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














       

      draft saved


      draft discarded


















      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

























      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:



      enter image description here






      share|improve this answer



























        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:



        enter image description here






        share|improve this answer

























          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:



          enter image description here






          share|improve this answer














          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:



          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 2 days ago

























          answered Nov 17 at 23:34









          esdd

          57.6k34485




          57.6k34485






















              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}


              enter image description here






              share|improve this answer

























                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}


                enter image description here






                share|improve this answer























                  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}


                  enter image description here






                  share|improve this answer












                  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}


                  enter image description here







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 17 at 23:48









                  egreg

                  698k8518573126




                  698k8518573126






























                       

                      draft saved


                      draft discarded



















































                       


                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      數位音樂下載

                      When can things happen in Etherscan, such as the picture below?

                      格利澤436b