6

I would like to create an inline brace command \inline{} for xelatex using TikZ. The difficult part is calculating the text width for the node without hardcoding it into the tikzpicture environment.

I would like:

  1. VARIABLE 1 Text width = Length of the Longest Word within node e.g. \node[decoration={brace},decoration,text centered,text width=VARIABLE1,]
  2. VARIABLE 2 Distance of brace from node to be the length of the longest word plus a little extra space for aesthetics. e.g. \p1=(bracetext.north), \p2=(bracetext.south) in ($(\x1+VARIABLE2,\y1)$) -- ($(\x2+VARIABLE2,\y2)$);
  3. Ideally the baseline of the node will be aligned such that the pointy part of the braces are aligned with the lines of the sentence (also for aesthetics).

Screenshot of Important Areas

\documentclass[handout]{beamer}
\usepackage{fontspec}

\usepackage{tikz}
\usetikzlibrary{chains,calc,trees,positioning,arrows,shapes.geometric,%
    decorations.pathreplacing,decorations.pathmorphing,shapes,%
    matrix,shapes.symbols}
\tikzset{%
    decoright/.style={decoration={brace},decorate},
    decoleft/.style={decoration={brace,mirror},decorate},
}
\newcommand{\inbrace}[1]{%
    \tikz{
        \node[decoration={brace},decoration,text centered,text width=3cm,](bracetext){\small#1};
        %\draw[decotop] (bracetext.north) to (bracetext.south);
        \draw[decoright] let
            \p1=(bracetext.north), \p2=(bracetext.south) in
            ($(\x1+2.5em,\y1)$) -- ($(\x2+2.5em,\y2)$);
        \draw[decoleft] let
            \p1=(bracetext.north), \p2=(bracetext.south) in
            ($(\x1-2.5em,\y1)$) -- ($(\x2-2.5em,\y2)$);
    }%
}%


\begin{document}

\begin{frame}
    \frametitle{Bound Morphemes versus Free Morphemes and Bound Roots}
    A \inbrace{root\\stem\\base} is a morpheme, which is more specifically a lexeme, to which we can add other morphemes in the form of affixes. In most cases, we are connecting affixes to the front (prefix) or back (suffix) of a lexeme, however, occassionally there are instances when we add them within a lexeme (infix).

\end{frame}

\end{document}

Sample Output: Sample Output

  • 1
    If you usually have three words like that you can use a single multipart node. Regarding the item 3 you can use \tikz[baseline=....] for adjusting the position where the picture meets the line. With all respect, it will never look good if you insist on inline version. – percusse Apr 16 '13 at 18:57
  • I am not sure what the multipart node is and I will have to read up on that. I did have a failed baseline attempt and I should have included that in my code and examples. Inline tikz is pretty important for flexibility. I think it will always look better than anything Powerpoint or Word could produce—though I am not sure what you mean here. It would be useful to have the baseline also calculated based on how many words are within the node. – Jonathan Komar Apr 16 '13 at 19:03
4

Explanation:

  • inner xsep = <distance between longest text and end of picture>
  • raise = <inner xsep> - <distance between longest text and brace>
  • The baseline option is used to align the text vertically.

Code

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing,decorations.pathmorphing}
\tikzset{%
  decoright/.style={
    decoration={
      brace,
      raise=-0.5em
    },
    decorate
  },
  decoleft/.style={
    decoration={
      brace,
      mirror,
      raise=-0.5em
    },
  decorate},
}
\newcommand{\inbrace}[2][middle]{%
  \tikz[baseline={(#1)}]{
    \node[
      draw=gray,% for debug
      align=center,
      inner xsep=1em,
      outer sep=+0pt,
      font=\small,
      name=bracetext
    ] {#2};
    \draw[decoleft]
        (bracetext.north west) -- coordinate (middle)
                                  (bracetext.south west);
    \draw[decoright]
        (bracetext.north east) -- (bracetext.south east);
  }%
}

\begin{document}
    A \inbrace{root\\stem\\base\\test} or 
    \inbrace[{[yshift=-.5ex]middle}]{root\\stem\\base\\test}?
\end{document}

Output

enter image description here

| improve this answer | |
  • Excellent work. Quite flexible when the quantity of words changes or the length of the words changes. The 2nd option \inbrace[{[yshift=-.5ex]middle}] looks better. Couldn't that be put in the top-matter such that the document code is "cleaner"? Also, I like how you managed to get rid of the calc library. Nicely done. – Jonathan Komar Apr 17 '13 at 12:14
  • 1
    @macmadness86 Sure just use \newcommand{\inbrace}[2][{[yshift=-.5ex]middle}]{% (the { } braces are important!) or for less flexibility use only one mandatory argument and set \tikz[baseline={([yshift=-.5ex]middle)}]{. – Qrrbrbirlbel Apr 17 '13 at 17:28
4

here is a solution without tikZ

\documentclass[handout]{beamer}
\usepackage{fontspec}
\newcommand\inbrace[1]{%
    \raisebox{\dimexpr0.5\height+0.5ex}{$\left\{\begin{tabular}{c}#1\end{tabular}\right\}$}}
\begin{document}

\begin{frame}
    \frametitle{Bound Morphemes versus Free Morphemes and Bound Roots}
    A \inbrace{root\\stem\\base} is a morpheme, which is more specifically a lexeme, to which we can add other morphemes in the form of affixes. In most cases, we are connecting affixes to the front (prefix) or back (suffix) of a lexeme, however, occassionally there are instances when we add them within a lexeme (infix).

\end{frame}
\end{document}

enter image description here

| improve this answer | |
4

The package delarray is very good for this, as it avoids doing any guess about the height of the material.

\documentclass[handout]{beamer}
\usepackage{delarray,array}
\newcommand{\inbrace}[1]{%
  $\begin{array}[b]\{{@{}>{$}c<{$}@{}}\}#1\end{array}$%
}

\begin{document}
\begin{frame}
\frametitle{Bound Morphemes versus Free Morphemes and Bound Roots}

Something before.

A \inbrace{root\\stem\\base} is a morpheme, which is more specifically a lexeme, to which
we can add other morphemes in the form of affixes. In most cases, we are connecting affixes
to the front (prefix) or back (suffix) of a lexeme, however, occassionally there are
instances when we add them within a lexeme (infix).

\end{frame}
\end{document}

With >{$}c<{$} we are saying that the column will be in text mode rather than in math mode.

enter image description here

| improve this answer | |

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.