我想调整 tikz 图形标题中矩形的位置。它应该稍微向下移动。此外,在标题中,它显示为“Fig.X 1-”。我想删除
多余的“1-”。如何做到这些?这是我的代码
\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
%\usepackage{caption}
\usepackage[labelsep=endash]{caption}
\renewcommand{\figurename}{Fig X.}
\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=0.18]
\foreach \x in {1,...,50}
\fill[red] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {1,5,7,10,16,22}
\fill[blue] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {2,14,35,44,46}
\fill[green] (1.1*\x,3) rectangle (1.1*\x+1,0);
\end{tikzpicture}
\caption{ \begin{tikzpicture}[scale=0.18] \fill[gray!=10] (0, 3 ) rectangle (0.75, 0 ); \end{tikzpicture}: X }
\end{figure}
\end{document}
答案1
像这样?
在标题之前tikzpicture
你应该插入命令\protect
:
\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage[labelsep=endash]{caption}
\renewcommand{\figurename}{Fig X.}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[scale=0.18]
\foreach \x in {1,...,50}
\fill[red] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {1,5,7,10,16,22}
\fill[blue] (1.1*\x,3) rectangle (1.1*\x+1,0);
\foreach \x in {2,14,35,44,46}
\fill[green] (1.1*\x,3) rectangle (1.1*\x+1,0);
\end{tikzpicture}
\caption{\protect\tikz{\fill[gray!30] (0,0) rectangle (0.15,2ex);}: X }
\end{figure}
\end{document}
无关: 我会绘制不缩放的图像,带有矩形的白色边框以及其大小的相对坐标:
\documentclass[preview]{standalone}
\usepackage{tikz}
\usepackage[labelsep=endash]{caption}
\renewcommand{\figurename}{Fig X.}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\foreach \x in {1,...,50}
\draw[white,fill=red] (0.2*\x,0) rectangle ++(0.2,0.6);
\foreach \x in {1,5,7,10,16,22}
\draw[white,fill=blue] (0.2*\x,0) rectangle ++(0.2,0.6);
\foreach \x in {2,14,35,44,46}
\draw[white,fill=green] (0.2*\x,0) rectangle ++(0.2,0.6);
\end{tikzpicture}
\caption{\protect\tikz{\fill[gray!30] (0,0) rectangle (0.15,2ex);}: X }
\end{figure}
\end{document}
编译结果和之前类似: