3

is it possible to make a comment-like section on the margin which encloses a paragraph and can deal with page breaking? The problem with the following code is that if an enclosed paragraph exceeds the length of the page the whole paragraph is transfered to the next page.

\documentclass[12pt]{article}

\usepackage{varwidth} %variable Größe von nodes
\usepackage{blindtext} % Für Sample Text
\usepackage{fancyhdr} %für Kopf- und Fußnoten.

\usepackage[a4paper,left=3cm,right=3cm,top=2cm]{geometry} %für Seitenabmessungen
\geometry{a4paper,left=3cm,right=5cm,top=2cm} %mehr rechter Rand

\usepackage{tikz} %für Vektorgraphiken. Siehe Abschnitt "TikZ"
\usetikzlibrary{shapes.geometric,calc,decorations.pathreplacing}

\raggedright %linksbündig

%Erzeugt eine Klammer um den gegebenen Text (Argument 1), die den Kopf (north) und den Fuß (south) des Textes einhüllt. Mittig und 10pt rechts des Textes wird ein weiterer Text in der Größe \scriptsize angezeigt (Argument 2)
\newcommand{\abschnitt}[2]{%
    \hspace*{-4pt}%
    \begin{tikzpicture}[decoration=brace]%
        \node[text width=\textwidth, align=left] (A) at (0,0) {#1};

        \begin{scope}[xscale=-1]
            \draw[decorate, very thick] (A.north east)-- (A.south east);
        \end{scope}

        \node[anchor=west] at ($(A.east)+(10pt,0)$) {
            \begin{varwidth}{3cm}
            \scriptsize#2
            \end{varwidth}
        };
    \end{tikzpicture}
}

\begin{document}
    \vspace*{2cm}
    \blindtext[3]
    \abschnitt{\blindtext}{ipsum}
\end{document}

Longer paragraphs will leave a greater gap on the previous page. The best approach would be something like this:

enter image description here

The bracket would start at the first page exceed to the next page, still enclosing the rest of the text. Optimally the comment will be automatically placed roughly at the half of the text height.

Laminator
  • 125
  • 2
    This is highly nontrivial, I think, and to my best knowledge the best way to do that is to look at this cool answer and customize it. You may also use this, but this is less clean. –  Jun 01 '18 at 17:23
  • 1
    Paragraph breaking is handled by \vsplit. I breaks a vbox into 2 vboxes to fit the first box to a given size. – John Kormylo Jun 01 '18 at 18:19
  • Thanks alot! I will probably check it out. The answerof Josef seems easier, but it probably will be of advantage to check out a way to figure it out with TikZ – Laminator Jun 03 '18 at 01:12

1 Answers1

3

Not sure if you you are bound to a Tikz solution, but the problem can be handled with PDF annotations and pdfcomment

\documentclass[12pt]{article}
\usepackage{blindtext} % Für Sample Text
\usepackage[a4paper,left=3cm,right=3cm,top=2cm]{geometry} %für Seitenabmessungen
\geometry{a4paper,left=3cm,right=5cm,top=2cm} %mehr rechter Rand
\usepackage{xcolor}
\usepackage{pdfcomment}
\begin{document}
    \vspace*{2cm}
    \blindtext[3]
    \begin{pdfsidelinecomment}[linebegin=/Circle,lineend=/Circle,linewidth=3bp,color=red,icolor=yellow]{comment}
    \blindtext
    \end{pdfsidelinecomment}
\end{document}

enter image description here

It can only handle one page break!

Josef
  • 7,432