2

I have a document where there are some sections with and some without subsections. When there are subsections, I want them (and all their content) to be indented. I have found several approaches to this which basically come down to the following two:

  1. Using a minipage

    This comes with two problems: Sections can't be broken over pages and floats can't float into or out of the minipage, so all floats would have to be placed between sections in the source as well as in the output.

  2. Using addmargin (or adjustwidth)

    (The addmargin environment is provided by KOMA-script and the adjustwidth environment by the changepage package.)

    This one doesn't have the problems a minipage has, but sectioning commands don't seem to work inside these environments at all. I get the error Something's wrong--perhaps a missing \item..

How can I achieve the indentation without having any of these problems?


MWE:

\documentclass[parskip=half]{scrartcl}

\begin{document}

\section{Using minipage}

\hfill\begin{minipage}{\dimexpr\textwidth-2cm}

\subsection{A Subsection}

First table declared here.

\begin{table}
    \centering
    \caption{some table}

    \begin{tabular}{c c}
        1, 1    &   1, 2    \\
        2, 1    &   2, 2    \\
    \end{tabular}
\end{table}

\subsection{Another Subsection}

Plain text.

\end{minipage}

\section{Using addmargin}

\begin{addmargin}[2cm]{0cm}

\subsection{A Subsection}

Second table declared here

\begin{table}
    \centering
    \caption{some table}

    \begin{tabular}{c c}
        1, 1    &   1, 2    \\
        2, 1    &   2, 2    \\
    \end{tabular}
\end{table}

\subsection{Another Subsection}

Plain text.

\end{addmargin}

\end{document}

Output:

The output of the MWE

schtandard
  • 14,892
  • See also http://tex.stackexchange.com/questions/588/how-can-i-change-the-margins-for-only-part-of-the-text and http://www.ctan.org/pkg/outlines – John Kormylo May 17 '14 at 15:43

1 Answers1

3

I'd probably use a list, something like this, although spacing could be adjusted

\documentclass[parskip=half]{scrartcl}

\let\xsubsection\subsection

\newcommand\xxsubsection[1]{\parbox{\dimexpr\textwidth-35pt}{\xsubsection{#1}}}
\newenvironment{sectext}{%
\renewcommand\subsection[1]{\item[{##1}]}%
\list{}{%
\itemindent0pt\relax
\listparindent\itemindent
\leftmargin2cm\relax
\let\makelabel\xxsubsection
}}{\endlist}
\begin{document}

\section{Using minipage}

\begin{sectext}

\subsection{A Subsection}

First table declared here.

\begin{table}
    \centering
    \caption{some table}

    \begin{tabular}{c c}
        1, 1    &   1, 2    \\
        2, 1    &   2, 2    \\
    \end{tabular}
\end{table}

\subsection{Another Subsection}

Plain text.


\subsection{A Subsection}

Second table declared here

\begin{table}
    \centering
    \caption{some table}

    \begin{tabular}{c c}
        1, 1    &   1, 2    \\
        2, 1    &   2, 2    \\
    \end{tabular}
\end{table}

\subsection{Another Subsection}

Plain text.

\end{sectext}

\end{document}
David Carlisle
  • 757,742