
나는 항상 독립형이 내 사진의 중심이 될 것이라고 생각합니다. 하지만 아래 예는 그렇지 않습니다.
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\usetikzlibrary{backgrounds}
\begin{document}
%jpg from http://www.murderousmaths.co.uk/magic/predictor%20cards%20template%20120.jpg
\def\infilename{/Users/e12714/Downloads/a.jpg}
\newsavebox{\graph}\savebox{\graph}{\includegraphics{\infilename}}
\newlength\gh\setlength\gh{\heightof{\usebox\graph}}
\newlength\gw\setlength\gw{\widthof{\usebox\graph}}
\newcounter{DEBUG}
\setcounter{DEBUG}{1}
\setcounter{DEBUG}{0}
\def\BL{0.16\gw,0.106\gh} % bottom left corner
\def\TR{0.92\gw,0.86\gh} % top right corner
\begin{tikzpicture}[framed,>=latex,
image/.style={anchor=south west,inner sep=0,outer sep=0}]
\ifthenelse{\theDEBUG = 1}{
% do nothing for debug purpose
}{
\clip (\BL) rectangle (\TR);
}
\node[image] (NI) {\usebox\graph};
\ifthenelse{\theDEBUG = 1}{
\draw[red,line width=2pt] (\BL) rectangle (\TR);
\begin{scope}[x={(NI.south east)},y={(NI.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1.001,1.001);
\foreach \x in {1,...,9} { \node [anchor=north] at (\x/10,0) {\x};}
\foreach \y in {1,...,9} { \node [anchor=east] at (0,\y/10) {\y};}
\end{scope}
}{}
\end{tikzpicture}
\end{document}
답변1
이는 실제 이미지 앞에 단락과 기타 공백이 있기 때문에 발생합니다.
\begin{document}
를 바로 앞에 두면 \begin{tikzpicture}
서문에서 공백이 무시되므로 문제가 사라집니다.
\documentclass[border=1mm]{standalone}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{ifthen}
\usetikzlibrary{backgrounds}
%jpg from http://www.murderousmaths.co.uk/magic/predictor%20cards%20template%20120.jpg
\def\infilename{example-image}
\newsavebox{\graph}\savebox{\graph}{\includegraphics{\infilename}}
\newlength\gh\setlength\gh{\heightof{\usebox\graph}}
\newlength\gw\setlength\gw{\widthof{\usebox\graph}}
\newcounter{DEBUG}
\setcounter{DEBUG}{1}
\setcounter{DEBUG}{0}
\def\BL{0.16\gw,0.106\gh} % bottom left corner
\def\TR{0.92\gw,0.86\gh} % top right corner
\begin{document}
\begin{tikzpicture}[framed,>=latex,
image/.style={anchor=south west,inner sep=0,outer sep=0}]
\ifthenelse{\theDEBUG = 1}{
% do nothing for debug purpose
}{
\clip (\BL) rectangle (\TR);
}
\node[image] (NI) {\usebox\graph};
\ifthenelse{\theDEBUG = 1}{
\draw[red,line width=2pt] (\BL) rectangle (\TR);
\begin{scope}[x={(NI.south east)},y={(NI.north west)}]
\draw[help lines,xstep=.1,ystep=.1] (0,0) grid (1.001,1.001);
\foreach \x in {1,...,9} { \node [anchor=north] at (\x/10,0) {\x};}
\foreach \y in {1,...,9} { \node [anchor=east] at (0,\y/10) {\y};}
\end{scope}
}{}
\end{tikzpicture}
\end{document}
또는 %
문제를 일으키는 빈 줄과 줄 끝에 기호를 배치할 수도 있지만 이 경우에는 필요하지 않습니다.