4

For some intentional form given poems it might be of certain use, if a frame could be drawn around the text and lines. This is not similar to a simple box with rectangular form, but suits the form of the shape of the lines written.

Thank you for some hints, if available.

MWE:

\documentclass{report}

\begin{document}

\centering This is\ an example \ how it can be\ and should\ appear.

\vspace*{\baselineskip} Without \ the lines \ around it. Can you\ imagine the\ lines?

\end{document}

The lines around the text need to be imagined. Is there a way or package to draw the lines closely to the text borders. Not a rectangular box!

See the image-file a follows: enter image description here

A first look into tikz package gave to following code possibility for a solution, but which seem not yet satisfying. Reason: The separation between the outer line and the inner text is not sufficient. I tried inner sep=5mm but without effect (not included at the code below).

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\begin{document}

\centering \tikzmark{A} \qquad \tikzmark{N}\ \tikzmark{B} This is \tikzmark{M}\ \tikzmark{C} an example \tikzmark{L} \ \tikzmark{D} how it can be \tikzmark{K}\ \tikzmark{E} and should \tikzmark{J}\ \tikzmark{F} appear. \tikzmark{I}\ \tikzmark{G} \qquad \tikzmark{H}

\tikz[remember picture] \draw[overlay,thick,rounded corners=6pt] (pic cs:A) -- (pic cs:B) -- (pic cs:C) -- (pic cs:D) -- (pic cs:E) -- (pic cs:F) -- (pic cs:G) -- (pic cs:H) -- (pic cs:I) -- (pic cs:J) -- (pic cs:K) -- (pic cs:L) -- (pic cs:M) -- (pic cs:N) -- cycle;

\vspace*{\baselineskip}

\tikzmark{a} \qquad \tikzmark{n}\ \tikzmark{b} Without \tikzmark{m}\ \tikzmark{c} the lines \tikzmark{l}\ \tikzmark{d} around it. Can you \tikzmark{k}\ \tikzmark{e} imagine the \tikzmark{j}\ \tikzmark{f} lines? \tikzmark{i}\ \tikzmark{g} \qquad \tikzmark{h}

\tikz[remember picture] \draw[overlay,thick,rounded corners=6pt] (pic cs:a) -- (pic cs:b) -- (pic cs:c) -- (pic cs:d) -- (pic cs:e) -- (pic cs:f) -- (pic cs:g) -- (pic cs:h) -- (pic cs:i) -- (pic cs:j) -- (pic cs:k) -- (pic cs:l) -- (pic cs:m) -- (pic cs:n) -- cycle;

\end{document}

enter image description here

  • 1
    Do you have a picture of how you want it to look? – mickep Dec 30 '23 at 22:08
  • Thank you for asking. No I can not reproduce it in LaTeX and do not have an image of it. But I added a MWE with which one can imagine what I mean. – Thomkrates Dec 30 '23 at 22:35
  • 1
    It’s not clear how you want the frame to look, if not just a rectangle — I can imagine several different ways of drawing an outline that more closely follows the text line lengths. Smooth curve, or a polygon of straight lines, or just horizontal/vertical lines? Staying convex around the whole paragraph, or with indentations where there are shorter lines within the paragraph? It would really be helpful to include an image showing what you’re envisaging — even say an MSPaint style image, or a scanned/photographed hand-drawn image, would help. – Peter LeFanu Lumsdaine Dec 30 '23 at 23:19
  • Ok, thank you for that input. If such a package needs to be written from scratch your imagination might be helpful for options of the package to decide what kind of frame it should be. Depending how complicated programming the code might be - Concerning my idea would be satisfied with smooth curves around the whole paragraph. But having options in a future package would be helpful for others who might use the same idea flexibly. (by the way I do not know how to insert jpg or pdf files here in these questions) – Thomkrates Dec 30 '23 at 23:41
  • I added an image file done with MSpaint. But the lower example is not smooth enough due to hand or mouse drawn lines. – Thomkrates Dec 31 '23 at 00:11
  • 2
    You coul put a \tikzmark at the start and end of each line (or assume symmetry) and connect them with smooth lines with tikz. – John Kormylo Dec 31 '23 at 04:40
  • 1
    Thank you., John. tikz seems to give plenty of packages named tikz-xyz. But the description in the latex documentary seems not to fullfil my need - at first sight. Which package do you mean? Or could you present an answer with code for a solution? When using \usepackage{tikz} and \tikzmark like you proposed, I get errors that \tikzmark is undefined control sequence – Thomkrates Dec 31 '23 at 11:42
  • \tikzmark is defined in package tikzmark and documented in the manual of that package. – cabohah Dec 31 '23 at 11:46
  • Ok, thank you, I found it. It comes close to the solution intended. tikz is immense. – Thomkrates Dec 31 '23 at 15:25
  • I tried around with inner sep=5mm but did not get any effect of it. How can the separation between line and text be handled? – Thomkrates Dec 31 '23 at 15:44

1 Answers1

5

\draw plot[smooth cycle, thick] coordinates { ... } may give better results, together with shifting the \tikzmarks a bit upward. With tension=... you might get some funny, maybe not quite forseeable effects.

enter image description here

\documentclass{report}
\usepackage{tikz}
\usetikzlibrary{tikzmark}
\newcommand\ml[3]{% marked line
  \raisebox{0.5ex}[0ex][0ex]{\tikzmark{#1}}\quad
  #2\quad
  \raisebox{0.5ex}[0ex][0ex]{\tikzmark{#3}}%
}
\begin{document}

\begin{center} \ml A{}N\ \ml B{This is}M\ \ml C{an example}L\ \ml D{how it can be}K\ \ml E{and should}J\ \ml F{appear.}I\ \ml G{}H \end{center} \tikz[remember picture,overlay] \draw plot[smooth cycle, thick] coordinates {(pic cs:A) (pic cs:B) (pic cs:C) (pic cs:D) (pic cs:E) (pic cs:F) (pic cs:G) (pic cs:H) (pic cs:I) (pic cs:J) (pic cs:K) (pic cs:L) (pic cs:M) (pic cs:N)};

\begin{center} \ml a{}n\ \ml b{Without}m\ \ml c{the lines}l\ \ml d{around it. Can you}k\ \ml e{imagine the}j\ \ml f{lines?}i\ \ml g{}h \end{center} \tikz[remember picture,overlay] \draw plot[smooth cycle, thick] coordinates {(pic cs:a) (pic cs:b) (pic cs:c) (pic cs:d) (pic cs:e) (pic cs:f) (pic cs:g) (pic cs:h) (pic cs:i) (pic cs:j) (pic cs:k) (pic cs:l) (pic cs:m) (pic cs:n)};

\begin{center} \ml 1{}{14}\ \ml 2{Without}{13}\ \ml 3{the lines}{12}\ \ml 4{around it. Can you}{11}\ \ml 5{imagine the}{10}\ \ml 6{lines?}9\ \ml 7{}8 \end{center} \tikz[remember picture,overlay] \draw plot[smooth cycle, thick, tension=3] coordinates {(pic cs:1) (pic cs:2) (pic cs:3) (pic cs:4) (pic cs:5) (pic cs:6) (pic cs:7) (pic cs:8) (pic cs:9) (pic cs:10) (pic cs:11) (pic cs:12) (pic cs:13) (pic cs:14)}; \end{document}

gernot
  • 49,614