5

My summary - just to get an idea

I am writing a summary mostly including equations but also some pictures. Now I would like to place the subsections including these pictures floating, such that the arrange themselves nicely.

I know how to place floating pictures. But is it possible to do the same to a whole subsection?

Thanks for your answers!

Edit: The floating section works. Altough in combination with {multicol} the newfloat{subsec} is no longer displayed.

\documentclass{article}
\usepackage{lipsum,caption,graphicx,float,titlesec}
\usepackage{multicol} %multiple columns
\newfloat{subsec}{h}{lop}

\begin{document}
\begin{multicols*}{3}
\tableofcontents
\listoffigures
\section{The Section}
Here is my non-floating introduction, which I place here just to 
demonstrate the margins.

\begin{subsec}[ht]
\subsection{Veni}
\lipsum[1-2]
\end{subsec}

\end{multicols*}
\end{document}
  • 1
    Welcome to TeX.SX! It is easier to help you if you add a minimal working example that takes the form \documentclass{...}\usepackage{....}\begin{document}...\end{document}. If possible, it should compile and have the minimum amount of code needed to illustrate your problem. This makes it much easier for people to troubleshoot your problem - and much more likely that they will! – Andrew Oct 16 '15 at 12:38
  • A float, in the LaTeX sense, must fit on a single page. So when you say "floating subsection", do you envision that this subsection must always appear in its entirety on a single page? – Steven B. Segletes Oct 16 '15 at 12:56
3

REVISED ANSWER

With the original answer (floated subsections and margin notes), I was unable to get multicols to encapsulate floats, and I don't see how that is possible. So, while the OP speaks of floats within columns, this revised answer takes a slightly different interpretation.

If the OP's goal is for subsections to remain as intact blocks, then one alternative to floating them would be to put them each in their own minipage, which will not break across columns. That is the approach I adopt here, but it also puts an added constraint on the OP to keep subsections under column in length.

My \mpar alternative to \marginpar is adopted here, as well, but adds an optional argument l or r to indicate which column the call is made from. In theory, 3 or more columns could be handled with a further rewrite.

So here is the result of this MWE:

\documentclass{article}
\usepackage{lipsum,caption,graphicx,tabto,multicol}
\newenvironment{subsec}[1][]{\par\noindent\begin{minipage}{5.9cm}}{\end{minipage}}
\def\mmargin{20pt}
\def\mwid{3cm}
\def\mposl{\dimexpr-\mmargin-\mwid}
\def\mposr{\dimexpr\textwidth+\mmargin}
\newcommand\mpar[2][l]{\tabto*{\csname mpos#1\endcsname}\smash{\parbox[t]{\mwid}{%
  \raggedright#2}}\tabto*{\TabPrevPos}}
\begin{document}
\tableofcontents
\listoffigures
\clearpage
\begin{multicols}{2}
\section{The Section}
 Here is my non-floating introduction, which I place here just to 
  demonstrate the margins.
\begin{subsec}[ht]
\subsection{Veni}
\lipsum[1]
Margin note call \mpar{Here is my longish margin note}
\lipsum[4]
\end{subsec}
\begin{subsec}[ht]
\subsection{Vidi}
\lipsum[3]
Margin note call \mpar[r]{Here is my second longish margin note}
\lipsum[4]
\end{subsec}
\begin{subsec}[ht]
\subsection{Vici}
\lipsum[4-5]
\begin{center}
\includegraphics[width=2in]{example-image-A}
\captionof{figure}{My Figure}
\end{center}
\end{subsec}
\end{multicols}
\end{document}

enter image description here

enter image description here

enter image description here

ORIGINAL ANSWER:

Perhaps something like this... Here I create a new float, subsec, using the answer described at Floating an algorithm?. Note that you cannot then place floating figures inside of the subsections, but can nonetheless get them there with \includegraphics and \captionof techniques, as I show on the final float.

As I mentioned in my comment to the OP's question, LaTeX floats must fit on a single page.

I have verified that it works when inserting \tableofcontents and \listoffigures at the top of the document.

Based on comment by the OP, EDITED to provide faux margin note \mpar capability (using the tabto package), by specifying \mpos for the location relative to the left margin of the text, and \mwid for the margin-note width. I just set the margin note as normal text, but \mpar can be easily adjusted for font size and style.

\documentclass{article}
\usepackage{lipsum,caption,graphicx,float,tabto}
\newfloat{subsec}{h}{lop}
\def\mpos{\dimexpr\textwidth+20pt}
\def\mwid{3cm}
\def\mpar#1{\tabto*{\mpos}\smash{\parbox[t]{\mwid}{%
  \raggedright#1}}\tabto*{\TabPrevPos}}
\begin{document}
%\tableofcontents
%\listoffigures
\section{The Section}
 Here is my non-floating introduction, which I place here just to 
  demonstrate the margins.
\begin{subsec}[ht]
\subsection{Veni}
\lipsum[1]
Margin note call \mpar{Here is my longish margin note}
\lipsum[2]
\end{subsec}
\begin{subsec}[ht]
\subsection{Vidi}
\lipsum[3]
\end{subsec}
\begin{subsec}[ht]
\subsection{Vici}
\lipsum[4-7]
\begin{center}
\includegraphics[width=2in]{example-image-A}
\captionof{figure}{My Figure}
\end{center}
\end{subsec}
\end{document}

enter image description here

enter image description here

  • Ok, your solution is working wonders! Where I'm starting to get problems is when combining it with the package {multicol}. I get the error: Package multicol Warning: Floats and marginpars not allowed inside `multicols' Do you have an Idea how to make this work? – GianAndrea Müller Oct 16 '15 at 14:25
  • @GianAndreaMüller I have developed a fake \marginpar substitute called \mpar, as described in my revised answer. I am no user of multicol, but will give that issue some additional thought, as well. – Steven B. Segletes Oct 16 '15 at 14:38
  • @GianAndreaMüller Could you clarify how you are hoping to use multicol? As in 1) use multicol inside of subsections or 2) use subsections inside of multicol? – Steven B. Segletes Oct 16 '15 at 14:45
  • @GianAndreaMüller I cannot make floats work inside of multicols. However, I propose an alternative using minipages instead of floats. Would that possibly work for you? – Steven B. Segletes Oct 16 '15 at 15:31
  • I was using multicols to divide my landscape-page into 3 colums. Like globally. Within these columns I wanted to have the floating subsections, hoping that they would arrange in a space-saving way... Maybe minipages would do the job - I will try it of course... :) – GianAndrea Müller Oct 16 '15 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.