tikzpicture: \foreach \draw [yshift=\n*\u] 좌표 1에서 중지

tikzpicture: \foreach \draw [yshift=\n*\u] 좌표 1에서 중지

이 MWE의 하단 섹션, 즉 아래의 모든 항목( % Image Ruler y)을 고려하세요.

\documentclass{article}

\usepackage{mwe} % Dummy images
\usepackage[skins]{tcolorbox}
\tcbuselibrary{raster}

\usepackage{tikz}
\usepackage{tikzpagenodes} % current page text area.center
\usetikzlibrary{calc} 
\pgfkeys{/tikz/savevalue/.code 2 args={\global\edef#1{#2}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\ShowHelps{0} %    1 'yes'        0   'no'

\newcommand{\UOneCoordinateX}{0.2}
\newcommand{\UOneCoordinateY}{0.09}
\newcommand{\UTwoCoordinateX}{0.2}
\newcommand{\UTwoCoordinateY}{0.284}

\newcommand{\GridSize}{0.05}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{tikzpicture}[
remember picture, overlay, % page center 1/3
shift={(current page.center)}, % page center 2/3
font=\sffamily,
Help/.style={font=\Huge, red}
]
\node[anchor=center, %south west,
inner sep=0 pt] (myimage) at (0,0) {

\begin{tcbitemize}[size=tight, halign=center, colback=gray, raster equal skip=0pt, raster left skip=0mm, raster right skip=0mm, raster width=1\textwidth, boxrule = 0pt, frame hidden]
\tcbitem \includegraphics[width=\textwidth]{example-image.jpg}
\tcbitem \includegraphics[width=\textwidth]{example-image.jpg}
\end{tcbitemize}  
};
\begin{scope}[x={($2*(myimage.east)$)},y={($2*(myimage.north)$)},
shift={(myimage.south west)} % page center 3/3
]

% Restrict the draw area
\clip (-0.1,-0.1) rectangle (1.1,1.1);

%%%%%ShowHelps
\path[] (\UOneCoordinateX,\UOneCoordinateY) coordinate(U1) -- (\UTwoCoordinateX,\UTwoCoordinateY) coordinate(U2);
\ifnum\ShowHelps=1 \draw[Help] (U1) circle(2pt) node[label=left:U1]{} -- (U2) circle(2pt) node[label=left:U2]{};\fi % show unitlength line

\path let \p1=($(U2)-(U1)$) in 
\pgfextra{  \pgfmathsetlengthmacro{\unitlength}{veclen(\x1,\y1)}   }
[savevalue={\u}{\unitlength}];
\ifnum\ShowHelps=1 \node[Help] at (0.725,0.25) {unitlength U1U2 = \u}; \fi%<--- show unitlength
\ifnum\ShowHelps=1 \draw[blue, transform canvas={xshift=2mm}] (U1) -- +(0,\u);\fi  % Test

% Image Ruler y
\draw[very thick] (0,0) coordinate(B) -- (0, 1);
\foreach \n in {0,1,...,10}{%%
\draw[very thick] ([yshift=\n*\u]B) -- +(-3mm,0) node[left]{
\ifnum\n=0 \else \ifnum\n=1 \n\,cm \else \n \fi\fi}; 
}%%
\foreach \n in {0.1,0.2,...,10}{%% 
\draw[] ([yshift=\n*\u]B) -- +(-1.5mm,0);
}%%

\end{scope}
\end{tikzpicture}

\end{document}

즉:

\draw[very thick] (0,0) coordinate(B) -- (0, 1);
\foreach \n in {0,1,...,10}{%%
\draw[very thick] ([yshift=\n*\u]B) -- +(-3mm,0) node[left]{
\ifnum\n=0 \else \ifnum\n=1 \n\,cm \else \n \fi\fi}; 
}%%
\foreach \n in {0.1,0.2,...,10}{%% 
\draw[] ([yshift=\n*\u]B) -- +(-1.5mm,0);
}%%

1in은 눈금자 \draw[very thick] (0,0) coordinate(B) -- (0, 1);의 두꺼운 수직선이 좌표 1에서 멈추도록 합니다. 정말 좋습니다!

1그러나 클리핑( )을 변경하지 않고 작은 선을 에서 멈추게 하는 방법은 무엇입니까 \clip (-0.1,-0.1) rectangle (1.1,1.1);?

10in 을 5로 변경하여 수행할 수 있지만 \foreach \n in {0.1,0.2,...,10}{%%, 얼마나 많은 숫자가 필요할지 미리 알 수 없기 때문에 그것은 내가 목표로 하는 것이 아닙니다. 내가 아는 것은 두꺼운 수직선이 를 사용할 1때 멈추는 것과 마찬가지로 y 좌표에서 멈추고 싶다는 것 뿐입니다 .1\draw[very thick] (0,0) coordinate(B) -- (0, 1);

스크린샷은 다음과 같습니다.

여기에 이미지 설명을 입력하세요

간단히 말해서:

y의 현재 좌표를 추출할 수 있는 방법이 필요합니다. 센티미터와 밀리미터를 반복적으로 증가시켜야 하는지 모르겠습니다. 제가 아는 것은 1에서 멈춰야 한다는 것뿐입니다.

답변1

사용방법decoration 여기에 이미지 설명을 입력하세요

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations}
\usepackage{mwe}

\newcount\tick
\newcount\majortick
\newif\ifmajortick

\pgfdeclaredecoration{ruler}{initial}{
  \state{initial}[
    width=0mm, next state=ruler,
    persistent precomputation={
      \tick=10
      \majortick=0
    }
  ]{
  }
  \state{ruler}[width=1mm,
    persistent precomputation={
      \ifnum \tick=10\relax
        \majorticktrue
        \tick=0
      \else
        \majortickfalse
      \fi
      \advance\tick by 1
    },
    persistent postcomputation={
      \ifnum \tick=10\relax
        \advance\majortick by 1
      \fi
    }
  ]{
    \ifmajortick
      \pgfscope
      \pgftransformrotate{-90}
      \pgftransformshift{\pgfpoint{-4mm}{0pt}}
      \pgfnode{rectangle}{east}{\the\majortick}{}{\pgfusepath{}}
      \endpgfscope
    \fi
    \pgfpathmoveto{\pgfpointorigin}
    \ifmajortick
      \pgfsetlinewidth{1pt}
      \pgfpathlineto{\pgfpoint{0pt}{3mm}}
    \else
      \pgfsetlinewidth{0.4pt}
      \pgfpathlineto{\pgfpoint{0pt}{1mm}}
    \fi
    \pgfusepath{stroke}
  }
  \state{final}{}
}

\begin{document}
\begin{tikzpicture}
\node[inner sep=0pt] (a) {\includegraphics[width=.5\textwidth]{example-image}};
\draw[postaction=decorate, decoration=ruler] (a.south west) -- (a.north west);
\end{tikzpicture}
\end{document}

답변2

\clip (-0.1,-0.1) rectangle (1.1,1.1);나는 tcolorbox 작업으로 인해 당신이 정말로 필요하다고 생각하지 않습니다 .

그러나 "Y축을 자르는 방법"이라는 질문에 대한 답변으로
이미지 높이인 "1" 포인트가 몇 개인지 알아야 합니다. 그리고 이는 코드에서 "단위 길이"가 측정된 것과 정확히 같은 방식으로 측정됩니다.

\path[draw=none] (0,0) coordinate(LL) -- (0,1) coordinate(UL);
\path let \p1=($(UL)-(LL)$) in 
\pgfextra{  \pgfmathsetlengthmacro{\ImageHeight}{veclen(\x1,\y1)}   }
[savevalue={\h}{\ImageHeight}];

\foreach \n in {0.1,0.2,...,10}{%%
\pgfmathsetmacro\Yshift{\n*\u}
\pgfmathsetmacro\YshiftTest{\n*\u < \h ?  1 : 0}
\ifnum\YshiftTest=1 \draw[] ([yshift=\Yshift]B) -- +(-1.5mm,0); \else\fi
}%%
\ifnum\ShowHelps=1
\draw[red] (LL) circle(2pt) node[below]{LL};
\draw[red] (UL) circle(2pt) node[above]{UL};
\node[right=3mm, Help] at (UL) {Image Height h=\h};    \fi 

여기에 이미지 설명을 입력하세요

\documentclass{article}

\usepackage{mwe} % Dummy images
\usepackage[skins]{tcolorbox}
\tcbuselibrary{raster}

\usepackage{tikz}
\usepackage{tikzpagenodes} % current page text area.center
\usetikzlibrary{calc} 
\pgfkeys{/tikz/savevalue/.code 2 args={\global\edef#1{#2}}}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\def\ShowHelps{1} %    1 'yes'        0   'no'

\newcommand{\UOneCoordinateX}{0.2}
\newcommand{\UOneCoordinateY}{0.09}
\newcommand{\UTwoCoordinateX}{0.2}
\newcommand{\UTwoCoordinateY}{0.284}

\newcommand{\GridSize}{0.05}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}

\begin{tikzpicture}[
remember picture, overlay, % page center 1/3
shift={(current page.center)}, % page center 2/3
font=\sffamily,
Help/.style={font=\large, text=red, fill=yellow}
]
\node[anchor=center, %south west,
inner sep=0 pt] (myimage) at (0,0) {

\begin{tcbitemize}[size=tight, halign=center, colback=gray, raster equal skip=0pt, raster left skip=0mm, raster right skip=0mm, raster width=1\textwidth, boxrule = 0pt, frame hidden]
\tcbitem \includegraphics[width=\textwidth]{example-image.jpg}
\tcbitem \includegraphics[width=\textwidth]{example-image.jpg}
\end{tcbitemize}  
};
\begin{scope}[x={($2*(myimage.east)$)},y={($2*(myimage.north)$)},
shift={(myimage.south west)} % page center 3/3
]

% Restrict the draw area
\clip (-0.1,-0.1) rectangle (1.1,1.1);
\ifnum\ShowHelps=1 \draw[red] (-0.1,-0.1) rectangle (1.1,1.1);\fi

%%%%%ShowHelps
\path[] (\UOneCoordinateX,\UOneCoordinateY) coordinate(U1) -- (\UTwoCoordinateX,\UTwoCoordinateY) coordinate(U2);
\ifnum\ShowHelps=1 \draw[red] (U1) circle(2pt) node[label=left:U1]{} -- (U2) circle(2pt) node[label=left:U2]{};\fi % show unitlength line

\path let \p1=($(U2)-(U1)$) in 
\pgfextra{  \pgfmathsetlengthmacro{\unitlength}{veclen(\x1,\y1)}   }
[savevalue={\u}{\unitlength}];
\ifnum\ShowHelps=1 \node[Help] at (0.3,0.5) {unitlength U1U2 = \u}; \fi%<--- show unitlength
\ifnum\ShowHelps=1 \draw[blue, transform canvas={xshift=2mm}] (U1) -- +(0,\u);\fi  % Test



% Image Ruler y
\draw[very thick] (0,0) coordinate(B) -- (0, 1);
\foreach \n in {0,1,...,10}{%%
\draw[very thick] ([yshift=\n*\u]B) -- +(-3mm,0) node[left]{
\ifnum\n=0 \else \ifnum\n=1 \n\,cm \else \n \fi\fi}; 
}%%

\path[draw=none] (0,0) coordinate(LL) -- (0,1) coordinate(UL);
\path let \p1=($(UL)-(LL)$) in 
\pgfextra{  \pgfmathsetlengthmacro{\ImageHeight}{veclen(\x1,\y1)}   }
[savevalue={\h}{\ImageHeight}];

\foreach \n in {0.1,0.2,...,10}{%%
\pgfmathsetmacro\Yshift{\n*\u}
\pgfmathsetmacro\YshiftTest{\n*\u < \h ?  1 : 0}
\ifnum\YshiftTest=1 \draw[] ([yshift=\Yshift]B) -- +(-1.5mm,0); \else\fi
}%%
\ifnum\ShowHelps=1
\draw[red] (LL) circle(2pt) node[below]{LL};
\draw[red] (UL) circle(2pt) node[above]{UL};
\node[right=3mm, Help] at (UL) {Image Height h=\h};    \fi 
\end{scope}
\end{tikzpicture}

\end{document}

관련 정보