1

I currently (try to) write a research paper for my college but I encountered a problem on LaTeX. When I use the multicol followed by two tcolorboxes, blank spaces are automatically inserted on the page in a very random way ... I would have liked the text to remain compact and not fill the entire page, even if it means that there is a big empty space at the end of the page (because I don't want a breakable tcolorbox).

The second picture includes the float=ht! option and the first does not include it (the code below includes it), but the result is still not what I expected.

Here is the MWE (% = optional) :

\documentclass[11pt,a4paper,dvipsnames]{book}
%\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{multicol} % Plusieurs colonnes
\usepackage[skins]{tcolorbox}

\newtcolorbox[auto counter, list inside=test, number within=chapter]{test}[1]{attach boxed title to top center={yshift=-8pt}, arc=10pt, boxed title style={arc=8pt}, colback=black!10, colbacktitle=black, colframe=black, enhanced, float=ht!, title=Test~\thetcbcounter~:~{#1}, top=10pt}

\begin{document}
\chapter{Chapter}
\section{Section}

\lipsum[1-4]

\begin{multicols}{2}
\lipsum[3]
\end{multicols}

hey

\begin{test}{First test}
\lipsum[4]
\end{test}

hey

\begin{test}{Second test}
\lipsum[5]
\end{test}

hey

\end{document}

enter image description hereenter image description here

2
  • Use brekable option for the boxes so the second box will be partially in the first page. Dec 29, 2021 at 3:37
  • It seems that you don't want to remove vertical justification everywhere, and only when a tcolorbox is at the end of a page, so solutions like e.g. inserting a vfill after the tcolorbox would not be good. In this case I think you need multiple compilation and something to remember if the box is at the end of the page.
    – user202729
    Dec 29, 2021 at 4:03

1 Answer 1

1

Adding float=ht! seems to do the trick.

a

\documentclass[11pt,a4paper,dvipsnames]{book}
%\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage{multicol} % Plusieurs colonnes
\usepackage[skins]{tcolorbox}

\newtcolorbox[auto counter, list inside=test, number within=chapter]{test}[1]{float=ht!, attach boxed title to top center={yshift=-8pt}, arc=10pt, boxed title style={arc=8pt}, colback=black!10, colbacktitle=black, colframe=black, enhanced, title=Test~\thetcbcounter~:~{#1}, top=10pt}

\begin{document}
    \chapter{Chapter}
    \section{Section}
    
    \lipsum[1-4]
    
    \begin{multicols}{2}
        \lipsum[3]
    \end{multicols}
    
    \begin{test}{First test}
        \lipsum[4]
    \end{test}
    
    \begin{test}{Second test}
        \lipsum[5]
    \end{test}
    
\end{document}
3
  • Thanks for your answer but i cannot use the float options because if I use it, the result is weird if I add text between each paragraph. I will modify the MWE to show you : I will add some "hey" in the text.
    – Dorian
    Dec 30, 2021 at 13:54
  • @Dorian for the second hey use hey\newpage. This is normal when using floats since the third tcolorbox does not fit in the page #2. If floats is not an option you need to do the layout manually to avoid blank spaces. I suggest you try the floats in a your real document to see how many manual interventions are needed. Jan 5, 2022 at 17:19
  • Thanks for your reply but I really need a non-manual and automatic method. I am writing a paper for my college, above all I write it occasionally on my phone on a simple text editor, you can understand that I cannot play at compiling it and see for each page what the result is.
    – Dorian
    Jan 6, 2022 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .