6

I created a TikZ picture using \newcommand and I want to use it as a subscript. The problem is that it is too big, is there a way I can make it smaller?

Here's what I have tried:

\documentclass[border = 5mm]{standalone}
\usepackage{tikz}
\newcommand{\test}{\begin{tikzpicture}
    \draw (0,0)--(1,1);
    \draw (0,1) -- (0.5-0.05,0.5+0.05);
    \draw (1,0) -- (0.5+0.05,0.5-0.05);
    \end{tikzpicture}}

\begin{document}
    $Something_{\test}$
\end{document}

Output

M. Al Jumaily
  • 4,035
  • 2
  • 11
  • 26
  • 1
    \documentclass{article} \usepackage{tikz} \begin{document} \newcommand{\test}[1][]{\begin{tikzpicture}[#1] \draw (0,0)--(1,1); \draw (0,1) -- (0.5-0.05,0.5+0.05); \draw (1,0) -- (0.5+0.05,0.5-0.05); \end{tikzpicture}} $X_{\test[scale=0.2]}$ \end{document}? –  May 26 '19 at 22:47

2 Answers2

4

Welcome to TeX-SE! Your proposal works nicely if you use scale to scale the picture down.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand{\test}[1][]{\begin{tikzpicture}[#1]
\draw (0,0)--(1,1);
\draw (0,1) -- (0.5-0.05,0.5+0.05);
\draw (1,0) -- (0.5+0.05,0.5-0.05);
\end{tikzpicture}}
$X_{\test[scale=0.2]}$
\end{document}

enter image description here

However, often one wants to define a new symbol that scales with the text and becomes bold when the surroundings are, adapts the color of is ambient text and so on. Here is a way of achieving this with your command as starting point.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\makeatletter
\DeclareRobustCommand{\checkbold}[1]{% https://tex.stackexchange.com/a/24635/121799
 \edef\@tempa{\math@version}\edef\@tempb{bold}%
 \ifx\@tempa\@tempb%
  \def#1{1}%
 \else
  \def#1{0}%
 \fi}
\makeatother 
\newcommand{\somedrawing}{(0,0)--(0.7em,0.7em)  (0,0.7em) -- (0.35em-0.07em,0.35em+0.07em)
 (0.7em,0) -- (0.35em+0.07em,0.35em-0.07em)}
\newcommand{\myX}{\checkbold\tmp%
\ensuremath{\mathrel{%
\mathchoice{%
\tikz{\draw[line width={1.2*(1+0.33*\tmp)*0.06em}]\somedrawing;}
}{%
\tikz{\draw[line width={1.2*(1+0.33*\tmp)*0.06em}]\somedrawing;}
}{%
\tikz{\draw[line width={1.2*(1+0.33*\tmp)*0.045em}]\somedrawing;}
}{%
\tikz{\draw[line width={1.2*(1+0.33*\tmp)*0.035em}]\somedrawing;}
}}}}
\newcommand{\test}{\begin{tikzpicture}
\draw[line width=0.07ex] ;
\end{tikzpicture}}
\begin{document}
$X_{\myX}$ {\Large $\myX_{\myX}$} {\boldmath $X_{\myX}$ \textcolor{blue}{\Large $\myX_{\myX}$}}
\end{document}

enter image description here

Further information can be found in the answers to this question, and I am using the TikZy answer from there.

2

Similar to @marmot's answer but the parameter passed (a number) is the scale-down size and you could simply the \test command without passing any parameters (the scale factor is set to 0.2 by default). Also, I have make the drawing of the command easier, I drew a thick white line and then a smaller black line.

Output

\documentclass[border = 5mm]{standalone}
\usepackage{tikz}
\newcommand{\test}[1][0.2]{%
    \begin{tikzpicture}[scale=#1]
        \draw[] (0,0)--(1,1);
        \draw[very thick, white] (1,0)--(0,1); % The white separation
        \draw[] (1,0)--(0,1);
    \end{tikzpicture}%
}

\begin{document}
    Default size \test, in mathmode: $Something_{\test[0.125]}$.
\end{document}
M. Al Jumaily
  • 4,035
  • 2
  • 11
  • 26