5

I searched this forum and found a similar question here: Adding slurs to words in a text

This describes how to add slurs at the bottom of a group of text characters using tikz package. I want to do the same but on the top of the group of text.

[FOLLOW-UP]: How do I extend the slur to extend over entries in multiple columns in tabular environment i.e. I want to do &\slur{P &M &G} with 3 columns having entries P, M and G and the slur extending over them? Neither Juan's or Steve's solution work as I get an error compiling.

thanks

  • Welcome to TeX.SE ! Looks like you need to change the anchor point (at least). / Either search here for anchor, to see more examples, or have a look into the manual at https://www.ctan.org/pkg/pgf . Yes, it's big, but it's straight forward to find ;-) – MS-SPO Aug 18 '21 at 06:18
  • Don't edit the question to ask more questions. Ask a new question instead. – user202729 Dec 30 '21 at 01:15

2 Answers2

8
\documentclass{article}
\usepackage{scalerel,stackengine}
\newcommand*{\slur}[1]{%
  \sbox0{#1}%
  \sbox2{\rotatebox[origin=bl]{90}{\stretchto{)}{\wd0}}}%
  \stackengine{0pt}{\vphantom{X}#1}%
  {\smash{\abovebaseline[0pt]{\copy2}}}{O}{c}{F}{F}{S}%
}

\begin{document}

See \slur{this}, or \slur{this one}.

\end{document}

enter image description here

8

I propose a TikZ solution. With a \slur macro that takes two arguments, the text below the slur and the color of the said slur. This macro computes and fills two arcs above the text, with customizable heights.

Something like this:

\documentclass{article}
\usepackage   {tikz}

% some parameters \def\H {0.5ex} % height, higher arc \def\h {0.3ex} % height, lower arc \def\vs{1.7ex} % vertical shift

% the slur \newcommand{\slur}[2][] % color (optional), text to be slurred {% <-- we don't want a space here \begin{tikzpicture} \node[inner sep=0,text depth=0,text height=\vs] (a) {#2}; \coordinate (A) at (a.north east); \path (A); \pgfgetlastxy{\x}{\y}; \pgfmathsetmacro\R{\x\x+\H\H)/2/\H} % radius, higher arc \pgfmathsetmacro\r{\x\x+\h\h)/2/\h} % radius, lower arc \pgfmathsetmacro\A{asin(\x/\R)} % angle, higher arc \pgfmathsetmacro\a{asin(\x/\r)} % angle, lower arc \fill[#1] (A) arc (90-\A:90+\A:\R pt) arc (90+\a:90-\a:\r pt); \end{tikzpicture}% <-- we don't want a space here either }

\begin{document} \slur{Slurred} text, more \slur{slurred text}, and a little slur: \slur{ab}.

\bigskip \Huge

\color{magenta} \slur[green]{Slurred} text, \color{blue} more \slur{slurred text}. \end{document}

enter image description here

Edit: Following campa's comment I changed the color to optional parameter. Of course, it's better this way.

Juan Castaño
  • 28,426