3

I want to fit the "N-1" into the box below if possible; if I use the solution \text{-}, namely 3/{N\text{-}1}, it gives me an error: Undefined control sequence: } (followed by: )

Is there a way to fix?

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}
\def\d{0.7cm} 
\tikzset{
  >=latex,
  font=\sffamily,
  mybox/.style={rectangle, fill=white, thin, draw, outer sep=0, minimum width = \d, minimum height = \d, inner sep=0},
}
\begin{document}
\begin{tikzpicture}
\foreach\k/\s in {
             0/1,  3/{N-1},  4/{N}
}{
        \node[mybox] (bc\k) at ($(-\k*\d, 0)$) {$S_{\s}$};
}

\end{tikzpicture}
\end{document}
6
  • Why don't you make your boxes a bit larger?
    – bmv
    Jan 19, 2018 at 17:54
  • 2
    The problem is that \text isn't defined. Use \textup instead of \text and it will work. Jan 19, 2018 at 17:55
  • font=\sffamily\small
    – Ignasi
    Jan 19, 2018 at 17:56
  • Making the boxes larger is an obvious solution but then the text looks weirdly small (my real example has S0, S1, S2, S3, S4, ... SN-1, SN and the SN-1 is the only one that needs squishing)
    – Jason S
    Jan 19, 2018 at 17:59
  • @HoodChatham thanks -- add answer + I'll accept.
    – Jason S
    Jan 19, 2018 at 18:09

2 Answers 2

4

You can use \text{-}, but you need amsmath.

\documentclass{standalone}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{calc, positioning}

\newcommand\dd{0.7cm} 
\tikzset{
  >=latex,
  font=\sffamily,
  mybox/.style={
    rectangle,
    fill=white,
    thin,
    draw, outer sep=0,
    minimum width = \dd,
    minimum height = \dd,
    inner sep=0
  },
}
\begin{document}
\begin{tikzpicture}
\foreach\k/\s in {
             0/1,  3/{N\text{-}1},  4/{N}
}{
        \node[mybox] (bc\k) at ($(-\k*\dd, 0)$) {$S_{\s}$};
}

\end{tikzpicture}
\end{document}

Don't do \def\d{...}.

enter image description here

2
  • could you expand on your "Don't do \def\d" comment?
    – Jason S
    Jan 19, 2018 at 18:53
  • @JasonS Using \def is never recommended: you risk redefining important commands without warning and, for this case, head scratching when your bibliography contains exotic names.
    – egreg
    Jan 20, 2018 at 9:07
1

The answer that you linked suggests using a \scalebox to shrink the minus sign only horizontally instead of vertically. You can define a custom macro like this:

\documentclass{article}
\usepackage{graphicx}
\def\sminus{\scalebox{0.75}[1.0]{\( - \)}}

\begin{document}
  $-8 \sminus 8$
\end{document}

To adjust the width of your minus sign to suit your liking, adjust the {0.75} value. The [1.0] is the vertical scale so that it stays the same "height."

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .