4

So I want to insert text that's not related to a subsection, but rather to the top section the subsection parts from. This is the idea:

\section{fruits}
All these are fruits:
\subsection{orange}
color orange
\subsection{grape}
color purple
\subsection{banana}
Yellow and long fruit
\end{subsection}
a fruit is a part of a flowering plant that derives from specific tissues of the flower, one or more ovaries, and in some cases accessory tissues
\section{foo}
\subsection{unrelated bar}

So what I want to be able to do, is make a short description, a few examples with subsections and explanations about them, and then, close the last subsection, and continue the explanation on what fruits are and, taking stuff from subsections, draw similarities. Is this possible? Thanks!

Edit: It has been suggested to use description and enumerate, but the problem here is that I want the subsections to contain item lists, descriptions and enumerations, and I also want the subsections to appear in the ToC so people can quickly jump to each detailed description of each fruit (in this example).

Edit 2: This is the ideal output generated with MS Word (I'm not sure, I'm assuming the person has used Word). enter image description here

As you can see, there's an space before after the end of the subsection 5.6, like if it was starting a new section, as well as the adequate indentation.

  • 3
    Not really. Of course you can do it anyway, just putting in perhaps a small vertical space or other marker, but latex sectioning only really marks the beginning of each section there is no end marker. – David Carlisle Mar 10 '13 at 11:45
  • 1
    May be you need descriptions – user11232 Mar 10 '13 at 11:46
  • 1
    I would use an enumerate instead of subsectios, or a last subsection called "Putting all toghether" or whatever is appropiate. – JLDiaz Mar 10 '13 at 11:49
  • 2
    Do you have a idea how the formatted output should look like? – Hendrik Vogt Mar 10 '13 at 12:00
  • +1 A very good observation about typesetting! Similar: You cannot insert subsection-less (section-level) text in between subsections. – Lover of Structure Mar 10 '13 at 14:49
4

What you aim at is not the usual structure. Usually, everything that is general to one section comes before all subsections.

A simple vertical space will not make it clear to the reader, that the former subsection has ended and we're structurally back on the section level. You should support your reader further.

Some possibilities:

  • Start a new subsection, that makes it clear. Something like "In general" or so.
  • Add vertical side lines or background or at least a horizontal line after the last specific subsection.

\documentclass{article}
\usepackage{environ}
\usepackage{xcolor}
\NewEnviron{specifics}{\colorbox{red}{\begin{minipage}{\textwidth}\BODY\end{minipage}}\par\noindent}
\begin{document}
\section{fruits}
\begin{specifics}
All these are fruits:
\subsection{orange}
color orange
\subsection{grape}
color purple
\subsection{banana}
Yellow and long fruit
\end{specifics}
a fruit is a part of a flowering plant that derives from specific tissues of the flower, one or more ovaries, and in some cases accessory tissues
\section{foo}
\subsection{unrelated bar}
\end{document}

Even if you do something like this, the Table of Contents might mislead the reader:

1. Fruits  -- 15

1.1 Orange -- 15

1.2 Grape -- 16

1.3 Banana -- 17

2. Foo -- 20

What happens on pages 18 and 19. Is it about Bananas or Fruits in general?

  • I don't know, why the code is not properly formatted. I clicked on the button. I also don't know why Foo on the second last line is 1. although I entered 2. – Toscho Mar 10 '13 at 13:03
  • Ideally, in page 17, it would be a detailed description of bananas and its propiertries (taking more pages if necessary, say part of page 18). Then, in page 18 through page 19 starts the drawing of conclusion and similarities between oranges, grapes and bananas, and a general view of this all. Maybe what I should do is put the similarities and conclusions in the upper section, with "fruits"? Is that the best approach even though the reader doesn't know what oranges, grapes and bananas are? – dfhsfhdsfdhsdfgjsfgjdsdfgjsfgj Mar 10 '13 at 13:05
  • 5
    I finally wrote \subsection{Conclusion} and there, drew similarities after analyzing each upper subsection. I think it's the most sane way to not confuse the reader. – dfhsfhdsfdhsdfgjsfgjdsdfgjsfgj Mar 10 '13 at 13:14
  • @Toscho: That's a markdown quirk, see this answer on meta, "Code blocks after lists". – Hendrik Vogt Mar 10 '13 at 13:20
0

What you ask is weird but easy to solve. Simply put the whole subsections in some environment, such as

\newenvironment{sect}{}{\par} 

Then, a cross-reference to a \label{xxx} after \section{yyy}\begin{sect}\subsection{zzz}...\end{sect} will not \reference the subsection "zzz" but the parent section "yyy", so "technically speaking", the label "xxx" (and the following text) is not part of any subsection.

As Toscho pointed, one problem with that approach is that coulb be not indications of where the subsection end, but you simply can end the environment with some special format. For instance, some as simple as:

\newenvironment{sect}{}{\par\centering ***\par } 

The other problem the ToC, can be also solved with \addcontentsline. A MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage{nameref}
\usepackage[colorlinks]{hyperref}
\newenvironment{sect}{}{\par} 
\begin{document}
\tableofcontents
\section{Fruits}
\begin{sect}\subsection{Apples}\lipsum[1-4]\end{sect}
\begin{sect}\subsection{Bananas}\lipsum*[5-8]\color{red}
And the subsection end here.\end{sect}
% where I am now ???
\addcontentsline{toc}{subsection}{More about \nameref{which?}}
\label{which?} The label of this line is still in section \nameref{which?}.
\lipsum[9]
\section{Meats}
\section{Fishes}
\end{document}

Anyway still could be confusing for the reader... My suggestion is that the environment for subsection should be a framed and/or colored breakable box: A way to do this is with tcolorbox. This is still compatible with lists and almost anything, except floats. Another MWE:

\documentclass{article}
\usepackage{lipsum}
\usepackage[most]{tcolorbox}
\usepackage{nameref}
\usepackage[colorlinks]{hyperref}
\begin{document}
\tableofcontents

\section{Fruits}\label{fruits}
\label{start} The label of this line is in section \nameref{start}.
\lipsum[2]
\begin{tcolorbox}[breakable,before skip=2em,after skip=2em]
\subsection{Apples}
 \label{manzanas} The label of this line is in subsection \nameref{manzanas}.
 \lipsum[3]
\begin{itemize}
    \item Golden    
    \item Royal 
    \item Red
\end{itemize}
\lipsum[4-5]
\end{tcolorbox}
\begin{tcolorbox}[breakable,before skip=2em,after skip=2em]
\subsection{Bananas}
 \label{plata-no} The label of this line is in subsection \nameref{plata-no}.
\lipsum[6]
\begin{itemize}
    \item Lantudan 
    \item Cavendish
    \item Plátano de Canarias
\end{itemize}
\lipsum[7-8]
\end{tcolorbox}

\label{fruits} The label of this line is still is in section \nameref{fruits}.
\addcontentsline{toc}{subsection}{More about \nameref{fruits}}
\lipsum[9]
\section{Meats}
\section{Fishes}
\end{document}
-1
\section*{} % no sale en el indice
  • 3
    Could you elaborate on how this helps solve the problem? And please translate the comment, since this site operates in English. – Teepeemm Oct 2 '18 at 19:49
  • 1
    Mhhh, I don't think this is the correct way to do this, even if it gives the expected output (and I'm not sure it actually gives the expected output in the first place)... It would also be great if you could explain what your solution does and why it helps in more detail. Since the language on this site is English it would really help if you could translate your answer into English, not everyone speaks Spanish. – moewe Oct 2 '18 at 20:06
  • Bienvenido a TeX.sx!, pepe. Este sitio solo admite respuestas en inglés. Y la costumbre es que las expliques un poco y/o pongas un minimal working example (MWE) que demuestre la solución, de modo lo entieda y pueda comprobar fácilmente hasta el más novato. – Fran Oct 2 '18 at 22:16

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.