How can I make an adjustbox enviroment with margins fit in textwidth?












4














I am trying to create an enviroment with colored background. I have defined it in two ways:



documentclass{article}

usepackage[x11names]{xcolor}
usepackage{adjustbox}
newsavebox{savedbox}

newenvironment{colbox1}[1]
{
begin{adjustbox}{minipage=[c]{textwidth},margin= 5mm 5mm 5mm 5mm, bgcolor=#1,env=center}
}
{
end{adjustbox}
}


newsavebox{savedbox}
newenvironment{colbox2}[1]
{
newcommandcolboxcolor{#1}
begin{lrbox}{savedbox}
begin{minipage}[c]{textwidth}
}
{
end{minipage}
end{lrbox}
begin{center}
colorbox{colboxcolor}{usebox{savedbox}}
end{center}
}

begin{document}
Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

begin{colbox1}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox1}

Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

begin{colbox2}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox2}

end{document}


I would like the box to have margin and fit the text width. In colbox1, if I write 0.8textwidth , I get a box that isn't larger than the text width. However I would like to make the colored background to have exactly the same width of the text. (If someone knows a specific way to create such boxes, I would also love to know.)



See this print image:
pdflatex output










share|improve this question




















  • 1




    Check the tcolorbox-package.
    – Ulrike Fischer
    May 6 '17 at 19:47
















4














I am trying to create an enviroment with colored background. I have defined it in two ways:



documentclass{article}

usepackage[x11names]{xcolor}
usepackage{adjustbox}
newsavebox{savedbox}

newenvironment{colbox1}[1]
{
begin{adjustbox}{minipage=[c]{textwidth},margin= 5mm 5mm 5mm 5mm, bgcolor=#1,env=center}
}
{
end{adjustbox}
}


newsavebox{savedbox}
newenvironment{colbox2}[1]
{
newcommandcolboxcolor{#1}
begin{lrbox}{savedbox}
begin{minipage}[c]{textwidth}
}
{
end{minipage}
end{lrbox}
begin{center}
colorbox{colboxcolor}{usebox{savedbox}}
end{center}
}

begin{document}
Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

begin{colbox1}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox1}

Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

begin{colbox2}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox2}

end{document}


I would like the box to have margin and fit the text width. In colbox1, if I write 0.8textwidth , I get a box that isn't larger than the text width. However I would like to make the colored background to have exactly the same width of the text. (If someone knows a specific way to create such boxes, I would also love to know.)



See this print image:
pdflatex output










share|improve this question




















  • 1




    Check the tcolorbox-package.
    – Ulrike Fischer
    May 6 '17 at 19:47














4












4








4







I am trying to create an enviroment with colored background. I have defined it in two ways:



documentclass{article}

usepackage[x11names]{xcolor}
usepackage{adjustbox}
newsavebox{savedbox}

newenvironment{colbox1}[1]
{
begin{adjustbox}{minipage=[c]{textwidth},margin= 5mm 5mm 5mm 5mm, bgcolor=#1,env=center}
}
{
end{adjustbox}
}


newsavebox{savedbox}
newenvironment{colbox2}[1]
{
newcommandcolboxcolor{#1}
begin{lrbox}{savedbox}
begin{minipage}[c]{textwidth}
}
{
end{minipage}
end{lrbox}
begin{center}
colorbox{colboxcolor}{usebox{savedbox}}
end{center}
}

begin{document}
Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

begin{colbox1}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox1}

Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

begin{colbox2}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox2}

end{document}


I would like the box to have margin and fit the text width. In colbox1, if I write 0.8textwidth , I get a box that isn't larger than the text width. However I would like to make the colored background to have exactly the same width of the text. (If someone knows a specific way to create such boxes, I would also love to know.)



See this print image:
pdflatex output










share|improve this question















I am trying to create an enviroment with colored background. I have defined it in two ways:



documentclass{article}

usepackage[x11names]{xcolor}
usepackage{adjustbox}
newsavebox{savedbox}

newenvironment{colbox1}[1]
{
begin{adjustbox}{minipage=[c]{textwidth},margin= 5mm 5mm 5mm 5mm, bgcolor=#1,env=center}
}
{
end{adjustbox}
}


newsavebox{savedbox}
newenvironment{colbox2}[1]
{
newcommandcolboxcolor{#1}
begin{lrbox}{savedbox}
begin{minipage}[c]{textwidth}
}
{
end{minipage}
end{lrbox}
begin{center}
colorbox{colboxcolor}{usebox{savedbox}}
end{center}
}

begin{document}
Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

begin{colbox1}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox1}

Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

begin{colbox2}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox2}

end{document}


I would like the box to have margin and fit the text width. In colbox1, if I write 0.8textwidth , I get a box that isn't larger than the text width. However I would like to make the colored background to have exactly the same width of the text. (If someone knows a specific way to create such boxes, I would also love to know.)



See this print image:
pdflatex output







minipage backgrounds adjustbox fit






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 11 mins ago









Martin Scharrer

198k45632814




198k45632814










asked May 6 '17 at 19:13









K. Sena

215




215








  • 1




    Check the tcolorbox-package.
    – Ulrike Fischer
    May 6 '17 at 19:47














  • 1




    Check the tcolorbox-package.
    – Ulrike Fischer
    May 6 '17 at 19:47








1




1




Check the tcolorbox-package.
– Ulrike Fischer
May 6 '17 at 19:47




Check the tcolorbox-package.
– Ulrike Fischer
May 6 '17 at 19:47










2 Answers
2






active

oldest

votes


















3














Using tcolorbox without frame and sharp corners (no. 2 with adjustable margins):



boxes



documentclass{article}

usepackage[x11names]{xcolor}
usepackage[most]{tcolorbox}

newtcolorbox{colbox}[1]{colback=#1,colframe=#1,sharp corners}
newtcolorbox{colbox2}[1]{colback=#1,colframe=#1,left=5mm,right=5mm,top=5mm,bottom=5mm,sharp corners}

begin{document}
Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

begin{colbox}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox}

Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

begin{colbox2}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox2}

end{document}





share|improve this answer























  • @Bobyandbob I don't exactly know which...
    – TeXnician
    May 6 '17 at 20:24










  • A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
    – Bobyandbob
    May 6 '17 at 20:31








  • 1




    @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
    – TeXnician
    May 6 '17 at 20:35



















0














If I understand you correctly, then you only need to reduce the minipage width by the left and right margin, i.e. use textwidth-10mm instead of textwidth.



documentclass{article}

usepackage[x11names]{xcolor}
usepackage{lipsum}% for example text
usepackage{adjustbox}

newenvironment{colbox1}[1]
{%
begin{adjustbox}{minipage=[c]{textwidth-10mm},margin= 5mm 5mm 5mm 5mm, bgcolor={#1},env=center}%
}
{%
end{adjustbox}%
}

begin{document}
lipsum[1]
begin{colbox1}{Cornsilk2}
Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
end{colbox1}
lipsum[2]

end{document}


Screenshot






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',
    autoActivateHeartbeat: false,
    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%2f368509%2fhow-can-i-make-an-adjustbox-enviroment-with-margins-fit-in-textwidth%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









    3














    Using tcolorbox without frame and sharp corners (no. 2 with adjustable margins):



    boxes



    documentclass{article}

    usepackage[x11names]{xcolor}
    usepackage[most]{tcolorbox}

    newtcolorbox{colbox}[1]{colback=#1,colframe=#1,sharp corners}
    newtcolorbox{colbox2}[1]{colback=#1,colframe=#1,left=5mm,right=5mm,top=5mm,bottom=5mm,sharp corners}

    begin{document}
    Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

    begin{colbox}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox}

    Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

    begin{colbox2}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox2}

    end{document}





    share|improve this answer























    • @Bobyandbob I don't exactly know which...
      – TeXnician
      May 6 '17 at 20:24










    • A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
      – Bobyandbob
      May 6 '17 at 20:31








    • 1




      @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
      – TeXnician
      May 6 '17 at 20:35
















    3














    Using tcolorbox without frame and sharp corners (no. 2 with adjustable margins):



    boxes



    documentclass{article}

    usepackage[x11names]{xcolor}
    usepackage[most]{tcolorbox}

    newtcolorbox{colbox}[1]{colback=#1,colframe=#1,sharp corners}
    newtcolorbox{colbox2}[1]{colback=#1,colframe=#1,left=5mm,right=5mm,top=5mm,bottom=5mm,sharp corners}

    begin{document}
    Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

    begin{colbox}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox}

    Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

    begin{colbox2}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox2}

    end{document}





    share|improve this answer























    • @Bobyandbob I don't exactly know which...
      – TeXnician
      May 6 '17 at 20:24










    • A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
      – Bobyandbob
      May 6 '17 at 20:31








    • 1




      @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
      – TeXnician
      May 6 '17 at 20:35














    3












    3








    3






    Using tcolorbox without frame and sharp corners (no. 2 with adjustable margins):



    boxes



    documentclass{article}

    usepackage[x11names]{xcolor}
    usepackage[most]{tcolorbox}

    newtcolorbox{colbox}[1]{colback=#1,colframe=#1,sharp corners}
    newtcolorbox{colbox2}[1]{colback=#1,colframe=#1,left=5mm,right=5mm,top=5mm,bottom=5mm,sharp corners}

    begin{document}
    Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

    begin{colbox}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox}

    Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

    begin{colbox2}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox2}

    end{document}





    share|improve this answer














    Using tcolorbox without frame and sharp corners (no. 2 with adjustable margins):



    boxes



    documentclass{article}

    usepackage[x11names]{xcolor}
    usepackage[most]{tcolorbox}

    newtcolorbox{colbox}[1]{colback=#1,colframe=#1,sharp corners}
    newtcolorbox{colbox2}[1]{colback=#1,colframe=#1,left=5mm,right=5mm,top=5mm,bottom=5mm,sharp corners}

    begin{document}
    Praesent fermentum erat rhoncus commodo feugiat. Etiam ut metus quis ex vehicula pretium. Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non, bibendum hendrerit urna. Aenean aliquet tempor augue laoreet posuere. Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend. Sed non ante tempus, congue nibh ac, finibus ipsum. Nunc quis pretium elit, a faucibus metus.

    begin{colbox}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox}

    Aliquam erat volutpat. Morbi blandit justo a ex imperdiet finibus. Sed libero urna, efficitur vitae eros sagittis, pulvinar tempor eros. Fusce fermentum eget ante vitae auctor. Donec vitae ante accumsan, pretium urna id, lacinia nunc. Aenean augue felis, pretium eget nisi non.

    begin{colbox2}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox2}

    end{document}






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 6 '17 at 20:34

























    answered May 6 '17 at 20:17









    TeXnician

    24.2k63084




    24.2k63084












    • @Bobyandbob I don't exactly know which...
      – TeXnician
      May 6 '17 at 20:24










    • A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
      – Bobyandbob
      May 6 '17 at 20:31








    • 1




      @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
      – TeXnician
      May 6 '17 at 20:35


















    • @Bobyandbob I don't exactly know which...
      – TeXnician
      May 6 '17 at 20:24










    • A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
      – Bobyandbob
      May 6 '17 at 20:31








    • 1




      @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
      – TeXnician
      May 6 '17 at 20:35
















    @Bobyandbob I don't exactly know which...
    – TeXnician
    May 6 '17 at 20:24




    @Bobyandbob I don't exactly know which...
    – TeXnician
    May 6 '17 at 20:24












    A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
    – Bobyandbob
    May 6 '17 at 20:31






    A inner margin between box and (box-)text. Like margin= 5mm 5mm 5mm 5mm for adjustbox.
    – Bobyandbob
    May 6 '17 at 20:31






    1




    1




    @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
    – TeXnician
    May 6 '17 at 20:35




    @Bobyandbob Now with adjustable margins. But I understood that the OP just desperately tried to get a box with some margin (like my first, not that tight as his second) which fits textwidth.
    – TeXnician
    May 6 '17 at 20:35











    0














    If I understand you correctly, then you only need to reduce the minipage width by the left and right margin, i.e. use textwidth-10mm instead of textwidth.



    documentclass{article}

    usepackage[x11names]{xcolor}
    usepackage{lipsum}% for example text
    usepackage{adjustbox}

    newenvironment{colbox1}[1]
    {%
    begin{adjustbox}{minipage=[c]{textwidth-10mm},margin= 5mm 5mm 5mm 5mm, bgcolor={#1},env=center}%
    }
    {%
    end{adjustbox}%
    }

    begin{document}
    lipsum[1]
    begin{colbox1}{Cornsilk2}
    Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
    end{colbox1}
    lipsum[2]

    end{document}


    Screenshot






    share|improve this answer


























      0














      If I understand you correctly, then you only need to reduce the minipage width by the left and right margin, i.e. use textwidth-10mm instead of textwidth.



      documentclass{article}

      usepackage[x11names]{xcolor}
      usepackage{lipsum}% for example text
      usepackage{adjustbox}

      newenvironment{colbox1}[1]
      {%
      begin{adjustbox}{minipage=[c]{textwidth-10mm},margin= 5mm 5mm 5mm 5mm, bgcolor={#1},env=center}%
      }
      {%
      end{adjustbox}%
      }

      begin{document}
      lipsum[1]
      begin{colbox1}{Cornsilk2}
      Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
      end{colbox1}
      lipsum[2]

      end{document}


      Screenshot






      share|improve this answer
























        0












        0








        0






        If I understand you correctly, then you only need to reduce the minipage width by the left and right margin, i.e. use textwidth-10mm instead of textwidth.



        documentclass{article}

        usepackage[x11names]{xcolor}
        usepackage{lipsum}% for example text
        usepackage{adjustbox}

        newenvironment{colbox1}[1]
        {%
        begin{adjustbox}{minipage=[c]{textwidth-10mm},margin= 5mm 5mm 5mm 5mm, bgcolor={#1},env=center}%
        }
        {%
        end{adjustbox}%
        }

        begin{document}
        lipsum[1]
        begin{colbox1}{Cornsilk2}
        Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
        end{colbox1}
        lipsum[2]

        end{document}


        Screenshot






        share|improve this answer












        If I understand you correctly, then you only need to reduce the minipage width by the left and right margin, i.e. use textwidth-10mm instead of textwidth.



        documentclass{article}

        usepackage[x11names]{xcolor}
        usepackage{lipsum}% for example text
        usepackage{adjustbox}

        newenvironment{colbox1}[1]
        {%
        begin{adjustbox}{minipage=[c]{textwidth-10mm},margin= 5mm 5mm 5mm 5mm, bgcolor={#1},env=center}%
        }
        {%
        end{adjustbox}%
        }

        begin{document}
        lipsum[1]
        begin{colbox1}{Cornsilk2}
        Pellentesque vitae est faucibus, sollicitudin odio in, elementum enim. Maecenas ornare lorem in nunc semper, at malesuada neque eleifend.
        end{colbox1}
        lipsum[2]

        end{document}


        Screenshot







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 29 '17 at 13:01









        Martin Scharrer

        198k45632814




        198k45632814






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f368509%2fhow-can-i-make-an-adjustbox-enviroment-with-margins-fit-in-textwidth%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

            Accessing regular linux commands in Huawei's Dopra Linux

            Can't connect RFCOMM socket: Host is down

            Kernel panic - not syncing: Fatal Exception in Interrupt