1

I would like to put a square bracketed border around some words in a paragraph and also have it around a whole centered paragraph, depending on the paragraph width. Example:

Bracket border example


enter image description here

Page breaks in paragraphs must be handled by "cutting" the bracketed border in two pieces.

I found some example done with tikz and framed. Maybe this approach can be used?

Any other ideas?

1

I think I have met all your requires here:

enter image description here

I have created a \newcommand called \annot (for your annotations, because that text looks like a screenplay or some theatrical text). You just need to put \annot{the text you want to put in the annotation} and it will generate the square brackets, the centering inside, and centering outside if the length of any line in the annotation is greater than 4cm. Maximum width inside the annotations is 13cm, then it jumps the line (if you haven't do it manually).

\annot can split at the end of the page, "cutting" the square brackets in two pieces. But this system is not perfect. It works as follows:

Multiline with 1 or more lines of 13cm splits well: enter image description here

Multiline with all the lines less than 13 cm can't preserve hbox so the brackets are not adjusted to the text, but It can splits well too:

enter image description here

If you have a short annotation (<= 4cm) followed by normal text, like ("Zum Neger". Ab!). You just need to put the text in a second pair of curly brackets: \annot{Zum Neger}{Ab!}

Code:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[german,activeacute]{babel}

\usepackage{varwidth}
\usepackage[many]{tcolorbox}

\tcbset{
    bracketstyle/.style={fonttitle=\bfseries, breakable, freelance, colback=white, colframe=white,
    toprule=0pt, bottomrule=0pt, boxrule=0pt, halign=center}
}

\tcbset{
    mstyle/.style={
    bracketstyle, 
    text width=13cm,
    overlay unbroken and first={
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=18pt]frame.north west) -- 
        ([yshift=-5pt,xshift=14pt]frame.north west) -- 
        ([yshift=5pt,xshift=14pt]frame.south west);
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=-18pt]frame.north east) -- 
        ([yshift=-5pt,xshift=-14pt]frame.north east) -- 
        ([yshift=5pt,xshift=-14pt]frame.south east);
    },
    overlay unbroken app={
        \draw[black!65!white,line width=0.7pt,line cap=rect]
        ([yshift=5pt,xshift=18pt]frame.south west) -- 
        ([yshift=5pt,xshift=14pt]frame.south west);
        \draw[black!65!white,line width=0.7pt,line cap=rect]
        ([yshift=5pt,xshift=-18pt]frame.south east) -- 
        ([yshift=5pt,xshift=-14pt]frame.south east);
    },
    overlay middle and last={
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=14pt]frame.north west) -- 
        ([yshift=5pt,xshift=14pt]frame.south west);
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=-14pt]frame.north east) -- 
        ([yshift=5pt,xshift=-14pt]frame.south east);
    },
    overlay last app={
        \draw[black!65!white,line width=0.7pt,line cap=rect]
        ([yshift=5pt,xshift=14pt]frame.south west) --
        ([yshift=5pt,xshift=18pt]frame.south west);
        \draw[black!65!white,line width=0.7pt,line cap=rect]
        ([yshift=5pt,xshift=-18pt]frame.south east) --
        ([yshift=5pt,xshift=-14pt]frame.south east);
    }   
}
}

\newtcolorbox{mannot}{
    mstyle
}

\newtcolorbox{lmannot}{
    mstyle, hbox,  left=14pt, right=14pt
}

\newtcolorbox{sannot}[1]{
    bracketstyle,
    hbox, 
    overlay unbroken={
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=16pt]frame.north west) -- 
        ([yshift=-5pt,xshift=12pt]frame.north west) -- 
        ([yshift=5pt,xshift=12pt]frame.south west) --
        ([yshift=5pt,xshift=16pt]frame.south west);
        \draw[black!65!white,line width=0.7pt]
        ([yshift=-5pt,xshift=-16pt]frame.north east) -- 
        ([yshift=-5pt,xshift=-12pt]frame.north east) -- 
        ([yshift=5pt,xshift=-12pt]frame.south east) node [yshift=0.315cm,black,right] {#1} --
        ([yshift=5pt,xshift=-16pt]frame.south east) ;
    }
}

\newcommand{\annot}[2]{
\sbox0{#1}  
\ifdim\wd0>4cm\relax
\ifdim\wd0<13cm\relax
\begingroup\centering\begin{lmannot}{#2}\begin{varwidth}{\textwidth}\centering \emph{#1} \end{varwidth} \end{lmannot} \endgroup
\else
\begingroup\centering\begin{mannot} \emph{#1} \end{mannot}\endgroup\fi
\else
\begin{sannot}{#2} \emph{#1} \end{sannot}\fi
}

\usepackage{vmargin}
\setmargins{3cm}          % Left margin 
{1.3cm}                   % Top margin   
{15.6cm}                  % Text width   
{23.42cm}                 % Text height   
{10pt}                    % Headers height
{1cm}                     % Space between headers and text   
{0pt}                     % Footnote height  
{2cm}                     % Space between footnote and text

\begin{document}

\annot{Schnell ab.\\ Kurze Pause. Leontine tritt von der Tür zurück, legt ab. Der Kellner öffnet die Tür von Garilan. Garilan tritt auf, verbeugt sich kurz vor Leontine. Der Neger, mit Garilans riesigem, zettelverklebtem Koffer beladen, folgt Garilan und dem Kellner.}
    
\noindent
KELLNER: Es sind unsere besten Räume, mein Herr -\\
GARILAN, \emph{zu Leontine}: Die Karawane steht übermorgen bereit
\annot{Zum Neger.}{Ab!} \annot{Neger setzt den Koffer ab.}

\noindent       
KELLNER: Zu den Schlafzimmern, zum Bad, mein Herr -\\
GARILAN, \emph{zum Neger}: Wie viel?\\
NEGER, \emph{zeigt >>sechs<<}: Sitta.\\
GARILAN, \emph{bedeutet}: Zu viel!\\
NEGER, \emph{zeigt >>fünf<<}: Chámsa.\\
GARILAN, \emph{bedeutet}: Zu viel!\\\\

\hrule\bigskip\bigskip

\noindent
GARILAN: Sacre nom de Dieu! Porco di diavolo! Allah il Allah! God save the King!\\
LEONTINE: Du wirst dich beschweren, Liebling!

\annot{Sie trägt Koffereinlangen ins Schlafzimmer. \\ Garilan öffnet.}

\noindent
GARILAN: Was wollen Sie denn?


    
\end{document}
| improve this answer | |
  • Hi! Thanks a lot! It seems you have done a great work. Please give me a few days to try it out! – Robert Schimpfle Oct 20 at 17:52
  • Helping new people in this community is a good way to give them a start point, LaTeX can be intimidating sometimes, especially at your learning start. Please let me know if you have any doubt – Á. Iborra Oct 20 at 18:29
  • Great, that works for me. I have been working with LaTeX for 2 years by now. I don't use pure LaTeX for the books, I have developed kind of "abstraction level" on it because of various reasons: LaTeX is not the only output format I require... Basically it is a Groovy script that converts a quite simple text format into LaTeX and other more simple formats. This also means less of LaTeX "hard core coding" for me. – Robert Schimpfle Oct 21 at 21:21

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