
저는 다음과 같은 멋진 눈송이 이미지(전체 크기 이미지는 약간 크지만 제가 하려는 일의 가장 좋은 예입니다)와 같이 내 이미지에 스케일 바를 추가하는 가장 좋은 방법을 찾으려고 노력하고 있습니다.
한 가지 가능성은 다른 프로그램을 사용하여 눈금 막대를 삽입하는 것입니다. 그러나 텍스트를 래스터 이미지의 일부로 저장하는 것보다 텍스트가 멋지고 또렷한지 확인하고 싶습니다. 또한 미리 눈금 막대를 삽입하면 LaTeX가 이미지 크기를 조정할 때 텍스트 크기가 조정됩니다.
지금까지 이 작업을 쉽게 수행할 수 있는 기존 명령이나 패키지를 찾을 수 없었습니다. 이미지의 실제 크기를 지정하고 축척 막대의 크기를 계산하고 싶습니다.
나만의 매크로를 작성해야 한다면 다음부터 시작하겠습니다.과장된 패키지
나는 올바른 방향으로 가고 있는가?
편집 2:
TikZ에 익숙해진 후 제가 생각해낸 매크로는 다음과 같습니다.
\usepackage{tikz}
\usepackage{siunitx}
% Inserts a scale bar into an image
% Optional argument 1: the colour of the bar and text
% Argument 2: an \includegraphics command
% Argument 3: the real world width of the image
% Argument 4: the length of the scale bar
% Argument 5: the units in which the scale bar is measured
\newcommand{\scalebar}[5][white]{
\begin{tikzpicture}
\draw (0,0) node[anchor=south west,inner sep=0] (image) { #2 };
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\fill [#1] (0.05,0.2cm) rectangle (#4/#3+0.05,0.4cm);
\draw [#1] (0.05,0.4cm) node[anchor=south west] { \SI{#4}{#5} };
\end{scope}
\end{tikzpicture}
}
여기서는 단위 조합(cm와 이미지 크기의 분수)을 사용하고 있습니다. 이 측면이 좀 더 우아할 수 있을 것 같지만 지금 가지고 있는 것만으로도 제 목적에 충분합니다.
답변1
텍스트를 읽기 어려워질 때를 대비해 투명한 배경을 추가하기 위해 매크로를 약간 조정했습니다.
\newcommand{\scalebarbackground}[6][white]{
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] (image) { #2 };
\begin{scope}[x={(image.south east)},y={(image.north west)}]
\fill [fill=blue, fill opacity=0.5] (0.04,1.3em) rectangle (#5*#4/#3+0.04,0.1em);
\draw [#1, line width=0.2em] (0.04,1.2em) -- node[below,inner sep=0.1em, font=\footnotesize] {\SI{#5}{#6}} (#5*#4/#3+0.04,1.2em);
\end{scope}
\end{tikzpicture}
}
결과 스케일바는 다음과 같습니다.
자세한 정보와 배경 없는 스케일바는 내 요점을 참조하세요.https://gist.github.com/rbnvrw/00312251b756f6b48084#file-latexscalebars-md