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

1
  • 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}?
    – user121799
    May 26 '19 at 22:47
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
  • 1
    Works perfect, thanks! May 27 '19 at 1:43
  • 1
    @AnaEmiliadeOrellana Glad to hear! If this answer works for you, could you perhaps consider accepting it by clicking on the check mark left of it?
    – user121799
    May 27 '19 at 2:37
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}
5
  • Thank you so much! May 27 '19 at 1:43
  • 2
    I think that the OP's way of drawing this is better since it does also look good on a non-white background.
    – user121799
    May 27 '19 at 2:45
  • 1
    That's very true, I just thought that it might be a bit easier in terms of coding. Is there another (easier) way to obtain the result that also renders well on non-white background? May 27 '19 at 2:49
  • 1
    Yes, dash pattern.
    – user121799
    May 27 '19 at 4:54
  • 1
    Oh true, thanks! May 27 '19 at 8:44

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.