6

Is there a way (with tikz) to get an effect like shown in the following image?

enter image description here

I.e. what command \inserteffect would yield that effect instead of just inserting in brackets as is the case for the following MWE (pdflatex):

\documentclass{article}
\newcommand{\inserteffect}[1]{(#1)}
\begin{document}
Here some \inserteffect{very nice} text.
\end{document}
  • Welcome to TeX.SX! Please help us help you and add a minimal working example (MWE) that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – user31729 Jul 5 '15 at 20:34
  • This can be done even without TikZ. It's not clear (at least to me) what do you mean with "later added". Can you please explain more clearly your intent (is this for a presentation, for example?, should the text and the brace appear after the "main" text?). – Gonzalo Medina Jul 5 '15 at 20:40
  • @GonzaloMedina, I tried to clarify. It should appear at the same time. – aguestforfun Jul 5 '15 at 20:45
  • @ChristianHupfer, sorry, I've added a MWE. – aguestforfun Jul 5 '15 at 20:45
11

Something like this? This does use TikZ, even though that is really overkill.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\begin{document}

  Yn y fan hon, mae\tikzmark{a} \tikzmark{b}geiriau.

  \hskip 5em\tikzmark{c}testun neis iawn\tikzmark{d}

  \begin{tikzpicture}[overlay, remember picture]
    \draw ([xshift=-.25em]{pic cs:c}) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]$({pic cs:a})!1/2!({pic cs:b})$) [out=-85, in=90] to ([yshift=.25em, xshift=.25em]{pic cs:d}) -- ++(0,-.25em);
  \end{tikzpicture}
\end{document}

geiriau

EDIT

Here's a version which works with a single command. However, you need to ensure that sufficient vertical space is left for the text to fit.

The command takes 2 arguments. The first is a unique name for that point on the page. The second is the text.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [inner ysep=.1em] at ([yshift=-1em]{pic cs:#1}) {#2};
    \draw (#1-1.south west) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.25em]#1-1.south east) -- ++(0,-.25em);
  }%
}
\begin{document}

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.\bigskip

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.
\end{document}

geiriau bendigedig

EDIT 2

If you really want to squeeze it between lines of text, you can. However, I don't see much point in doing this as both the text and the addition will tend quickly towards the illegible.

But, heck, this site is about the technical implementation of ideas in TikZ, however batty they may be.

\documentclass[welsh]{article}
\usepackage{tikz,babel}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [font=\tiny, inner xsep=.1em, inner ysep=.05em] at ([yshift=-.35em]{pic cs:#1}) {#2};
    \draw [thin] (#1-1.south west) -- ++(0,.075em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.075em]#1-1.south east) -- ++(0,-.075em);
  }%
}
\begin{document}

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.

  Y mae llawer o eiriau mewn ieithoedd --- hyd yn oed yn un ohonynt.
\end{document}

batty

EDIT 3

Here's a version which assumes double-spacing and uses \footnotesize for the inserted text. Although still somewhat squeezed, around about this seems to me a reasonable compromise.

\documentclass[welsh]{article}
\usepackage{tikz,babel,setspace}
\usetikzlibrary{calc,tikzmark}
\newcommand\neis[2]{%
  \tikzmark{#1}%
  \tikz[remember picture,overlay]{%
    \node (#1-1) [inner xsep=.2em, inner ysep=.05em, font=\footnotesize] at ([yshift=-.65em]{pic cs:#1}) {#2};
    \draw [thin] (#1-1.south west) -- ++(0,.25em) [out=90, in=-95] to ([yshift=.25em]{pic cs:#1}) [out=-85, in=90] to ([yshift=.25em]#1-1.south east) -- ++(0,-.25em);
  }%
}
\begin{document}
  \doublespacing

  Yn y fan hon, mae \neis{a}{testun neis iawn} geiriau.

  Dyma'r \neis{b}{geiriau bendigedig} testun arall.

  Y mae llawer o eiriau mewn ieithoedd --- hyd yn oed yn un ohonynt.
\end{document}

saner

| improve this answer | |
  • Nice! Can this be transformed into one command one just places in the text like shonw in the MWE? – aguestforfun Jul 5 '15 at 20:53
  • @aguestforfun What about the text or whatever which is otherwise below the line? Should this take space or not? – cfr Jul 5 '15 at 20:56
  • Ideally 'testun neis iawn' should squeeze between the surrounding lines of text. – aguestforfun Jul 5 '15 at 20:59
  • @aguestforfun See edit. You need to allow space for it, though. I'm not sure how you could make it look like your target image and fit between the lines of text since the image you showed has the text -to-be-squeezed in the same size as the text on the line. If you double space or something, of course that would work and you would need to manually ensure sufficient space in particular instances. – cfr Jul 5 '15 at 21:37
  • @aguestforfun See also edit 2. – cfr Jul 5 '15 at 21:40

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.