
그림 생성 및 참조를 단순화하기 위해 다음 코드를 사용하고 있습니다.
\newenvironment{figcontext}[1]{%
\newcommand{\thefig}{#1}%
\newcommand{\crefsub}[1]{\cref{\thefig}.##1}%
\newcommand{\Crefsub}[1]{\Cref{\thefig}.##1}%
}{}
\newenvironment{cfig}[1]{%
\begin{figcontext}{#1}%
\begin{figure}[h!tb]% only 'H' is respected
\centering%
}{%
\label{\thefig}%
\end{figure}%
\end{figcontext}%
}
내 모든 수치를cfig
대부분의 그림이 별도의 페이지로 이동됩니다.멀리소스 코드의 원래 위치에서 벗어났습니다. 그림 배치가 (분명히) 주변 환경의 영향을 받는 이유는 무엇입니까? 유연성을 figure
완전히 잃지 않으면서 이 동작을 어떻게 해결할 수 있습니까?
답변1
옵션 목록에 p가 없으면 하나의 큰 숫자가 다음 모든 숫자를 끝까지 강제할 수 있습니다. 예로서:
\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{figure}[thb!] %compare with [thb!p]
\rule{1cm}{0.98\textheight}
\caption{blub}
\end{figure}
\lipsum[1]
\begin{figure}[thb!]
blbl
\caption{blub}
\end{figure}
\lipsum\lipsum
\end{document}
답변2
전체 문서의 모든 그림을 환경에 포함시키려는 경우 -environment를 cfig
재정의할 수도 있습니다 figure
. 또한 환경 내부를 둘러쌀 필요가 없으며 전역적으로 정의할 수 있습니다(대신 사용할 \crefsub
수도 있음 ) . 이러한 변경 사항이 배치 문제에 영향을 미치는지 여부는 알 수 없습니다.\Crefsub
fig.~\thefigure
\cref
제안된 변경 사항은 다음과 같습니다.
\documentclass{article}
% for MWE
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{todonotes}
\usepackage{tikz}
\usepackage{cleveref}
%\newcommand{\crefsub}[1]{fig.~\thefigure.#1}% without using cref
%\newcommand{\Crefsub}[1]{Figure~\thefigure.#1}% without using cref
\newcommand{\crefsub}[2][\myfiglabel]{\cref{#1}.#2}% with using cref
\newcommand{\Crefsub}[2][\myfiglabel]{\Cref{#1}.#2}% with using cref
\let\figurebak\figure
\let\endfigurebak\endfigure
\renewenvironment{figure}[2][tbhp]{
\def\myfiglabel{#2}%
\begin{figurebak}[#1]%
\centering%
}{%
\label{\myfiglabel}%
\end{figurebak}%
}
\begin{document}
\blindtext[1]
\blindtext[1]
\blindtext[1]
\begin{figure}{fig:label}
\begin{tikzpicture}[yscale=1.5]
\draw [help lines, <->] (0,0) -- (6.5,0) node{a};
\draw [help lines, ->] (0,-1.1) -- (0,1.1) node{b};
\draw [green,domain=0:2*pi] plot (\x, {(sin(\x r)* ln(\x+1))/2});
\draw [red,domain=0:pi] plot (\x, {sin(\x r)});
\draw [blue, domain=pi:2*pi] plot (\x, {cos(\x r)*exp(\x/exp(2*pi))});
\end{tikzpicture}
\caption{caption to my fig. Please note \Crefsub{a} and \crefsub{b}}
\end{figure}
See \cref{fig:label} as well as \crefsub[fig:label]{a}.
\blindtext[1]
\blindtext[1]
\blindtext[1]
\end{document}