4

If I use this code,

\documentclass{article}
\usepackage{tikz}
\usepackage{multicol,float}
\usepackage{etoolbox}% provides \preto

\usetikzlibrary{shapes,backgrounds}

\tikzset{
    every node/.style={midway},
    every path/.style={fill=yellow},
    mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow,node on layer=foreground},
}

\begin{document}

\begin{figure}[H]
\begin{tikzpicture}[scale = 4]
\draw (0.445041,0.801937) rectangle (0,1) node[mid] {$1$};
\draw (0.692021,0.356896) rectangle (1,1) node[mid] {$2$};
\draw (0.692021,0.356895) rectangle (0,0) node[mid] {$3$};
\draw (0.137063,0.158832) rectangle (0,1) node[mid] {$4$};
\draw (0.384043,0.713791) rectangle (1,0) node[mid] {$5$};
\draw (0.829084,0.515727) rectangle (0,1) node[mid] {$6$};
\draw (0.521105,0.872622) rectangle (0,0) node[mid] {$7$};
\end{tikzpicture}
\centering
\caption{M1}
\end{figure}

\end{document}

the result as for the caption is "Figure 1: M1". Is it possible to change it to just "M1"?

1
  • 2
    What has this got to do with TikZ? TikZ doesn't interact with figure caption titles.
    – user10274
    Jul 12, 2015 at 18:44

2 Answers 2

4

Three options; the first two, loading the caption package, and the third one with no packages:

  1. Use \caption*:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{backgrounds}
    \usepackage{multicol,float}
    \usepackage{etoolbox}% provides \preto
    \usepackage{caption}
    
    \usetikzlibrary{shapes,backgrounds}
    
    \tikzset{
        every node/.style={midway},
        every path/.style={fill=yellow},
        mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow},
    }
    
    \begin{document}
    
    \begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale = 4]
    \draw (0.445041,0.801937) rectangle (0,1) node[mid] {$1$};
    \draw (0.692021,0.356896) rectangle (1,1) node[mid] {$2$};
    \draw (0.692021,0.356895) rectangle (0,0) node[mid] {$3$};
    \draw (0.137063,0.158832) rectangle (0,1) node[mid] {$4$};
    \draw (0.384043,0.713791) rectangle (1,0) node[mid] {$5$};
    \draw (0.829084,0.515727) rectangle (0,1) node[mid] {$6$};
    \draw (0.521105,0.872622) rectangle (0,0) node[mid] {$7$};
    \end{tikzpicture}
    \caption*{M1}
    \end{figure}
    
    \end{document}
    
  2. Declare the labelformat as empty using a local \captionsetup:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{backgrounds}
    \usepackage{multicol,float}
    \usepackage{etoolbox}% provides \preto
    \usepackage{caption}
    
    \usetikzlibrary{shapes,backgrounds}
    
    \tikzset{
        every node/.style={midway},
        every path/.style={fill=yellow},
        mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow},
    }
    
    \begin{document}
    
    \begin{figure}[H]
    \captionsetup{labelformat=empty}
    \centering
    \begin{tikzpicture}[scale = 4]
    \draw (0.445041,0.801937) rectangle (0,1) node[mid] {$1$};
    \draw (0.692021,0.356896) rectangle (1,1) node[mid] {$2$};
    \draw (0.692021,0.356895) rectangle (0,0) node[mid] {$3$};
    \draw (0.137063,0.158832) rectangle (0,1) node[mid] {$4$};
    \draw (0.384043,0.713791) rectangle (1,0) node[mid] {$5$};
    \draw (0.829084,0.515727) rectangle (0,1) node[mid] {$6$};
    \draw (0.521105,0.872622) rectangle (0,0) node[mid] {$7$};
    \end{tikzpicture}
    \caption{M1}
    \end{figure}
    
    \end{document}
    
  3. Don't use \caption at all; simply place the text:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{backgrounds}
    \usepackage{multicol,float}
    \usepackage{etoolbox}% provides \preto
    
    \usetikzlibrary{shapes,backgrounds}
    
    \tikzset{
        every node/.style={midway},
        every path/.style={fill=yellow},
        mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow},
    }
    
    \begin{document}
    
    \begin{figure}[H]
    \centering
    \begin{tikzpicture}[scale = 4]
    \draw (0.445041,0.801937) rectangle (0,1) node[mid] {$1$};
    \draw (0.692021,0.356896) rectangle (1,1) node[mid] {$2$};
    \draw (0.692021,0.356895) rectangle (0,0) node[mid] {$3$};
    \draw (0.137063,0.158832) rectangle (0,1) node[mid] {$4$};
    \draw (0.384043,0.713791) rectangle (1,0) node[mid] {$5$};
    \draw (0.829084,0.515727) rectangle (0,1) node[mid] {$6$};
    \draw (0.521105,0.872622) rectangle (0,0) node[mid] {$7$};
    \end{tikzpicture}\par\medskip
    M1
    \end{figure}
    
    \end{document}
    

    In this last case, if you don't want flotation, you could also simply use a minipage with centered content:

    \documentclass{article}
    \usepackage{tikz}
    \usetikzlibrary{backgrounds}
    \usepackage{multicol,float}
    \usepackage{etoolbox}% provides \preto
    \usepackage{caption}
    
    \usetikzlibrary{shapes,backgrounds}
    
    \tikzset{
        every node/.style={midway},
        every path/.style={fill=yellow},
        mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow},
    }
    
    \begin{document}
    
    \noindent\begin{minipage}{\linewidth}
    \centering
    \begin{tikzpicture}[scale = 4]
    \draw (0.445041,0.801937) rectangle (0,1) node[mid] {$1$};
    \draw (0.692021,0.356896) rectangle (1,1) node[mid] {$2$};
    \draw (0.692021,0.356895) rectangle (0,0) node[mid] {$3$};
    \draw (0.137063,0.158832) rectangle (0,1) node[mid] {$4$};
    \draw (0.384043,0.713791) rectangle (1,0) node[mid] {$5$};
    \draw (0.829084,0.515727) rectangle (0,1) node[mid] {$6$};
    \draw (0.521105,0.872622) rectangle (0,0) node[mid] {$7$};
    \end{tikzpicture}\par\medskip
    M1
    \end{minipage}
    
    \end{document}
    
3
  • In the last case, might one not just as well replace figure+\centering with the center environment? (No numbered caption or label, floating disabled -> figure not really needed.) Jul 12, 2015 at 18:26
  • @TorbjørnT. Yes, but I don't know whether flotation should be removed or not in the OP's mind. I'll add a remark. Jul 12, 2015 at 18:31
  • The first option is fine:-) Thank you.
    – Helena
    Jul 13, 2015 at 7:24
0

There is an option (5) which is using the exact same code minus these two lines without the \caption command:

\begin{figure}[H]
\end{figure}

Simply, {M1}

\documentclass{article}
\usepackage{tikz}
\usepackage{multicol,float}
\usepackage{etoolbox}% provides \preto

\usetikzlibrary{shapes,backgrounds}

\tikzset{
    every node/.style={midway},
    every path/.style={fill=yellow},
    mid/.style={midway, inner sep=2pt, outer sep=0,minimum size=1mm, fill=yellow,node on layer=foreground},
}

\begin{document}

\begin{tikzpicture}[scale = 4]
\draw (0.445041,0.801937) rectangle (0,1) node[midway] {$1$};
\draw (0.692021,0.356896) rectangle (1,1) node[midway] {$2$};
\draw (0.692021,0.356895) rectangle (0,0) node[midway] {$3$};
\draw (0.137063,0.158832) rectangle (0,1) node[midway] {$4$};
\draw (0.384043,0.713791) rectangle (1,0) node[midway] {$5$};
\draw (0.829084,0.515727) rectangle (0,1) node[midway] {$6$};
\draw (0.521105,0.872622) rectangle (0,0) node[midway] {$7$};
\end{tikzpicture}

{M1}

\end{document}
3
  • I don't understand your answer answer - if I remove \begin{figure}[H] and \end{figure} then the \caption{M1} throws an error as it's outside a float (unsurprisngly given we've just removed the figure environment) if this is a valid answer, please could you add an MWE to illustrate how it should work.
    – Dai Bowen
    Dec 9, 2016 at 23:26
  • absolutely! edited for completion.
    – Georges
    Dec 10, 2016 at 9:30
  • in addition, the provided tex encounters a problem due to the node on layer = foreground. the reason why i switched all node styles with just midway
    – Georges
    Dec 10, 2016 at 9:39

You must log in to answer this question.

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