
tikz 사진에서 노드의 높이를 계산하고 길이를 다른 길이로 나누어 카운터를 얻고 반올림하는 방법이 있습니까? 그렇다면 다양한 유형의 변수를 사용하여 계산하는 주제를 어디에서 읽을 수 있습니까?
예는 다음과 같습니다.
\documentclass [a4paper] {article}
\usepackage{calc}
\usepackage{tikz,pgf}
\usetikzlibary{arrows}
%in this case i want to do a framebox with the parameter of 1 line's length in a tikz pictures
%because i dont know how could i get the heigth of the node i try to calculate it by divide the full length of the text (what i got with the command \settototalheight from the calc package) by the length of 1 line (this is a parameter) so i got the number of lines(this is a value not a length so i cannot use the \divide command because the type of the variable)
\newlength \widthofone \fullwidth \heightoneline \fullheight
\nemcounters \numberoflines
\newcommand {\altframe}[2] { %#1 the text #2 the width of the lines
\widthofone=#2pt %im not sure how to convert a length from a value but i try to input the 2nd parameter into a length variable
\settototalheight{\heightoneline}{qwe} %i get the height of one line by the calc package
\setwidth{\totalwidth}{#1} %i calculate the width of the text
%And now i would divide \fullwidth by \widthofone ,if i would know how to do it, to get \numberoflines
%I would multiply it by \height to get \fullheight
\begin{tikzpictures}
\node[text width=#2pt] at (0,0) {#1};%i write out the text
\draw[->,color=black] (\fullwidth/2,\fullheight/2) -- (0-\fullwidth/2,\fullheight/2); %i draw out the lines (i use height/2 becouse of the fact that the (0,0) coordinate is the middle of the picture)
\draw[->,color=black] (\fullwidth/2,0-\fullheight/2) -- (0-\fullwidth/2,0-\fullheight/2);
\draw[->,color=black] (\fullwidth/2,\fullheight/2) -- (\fullwidth/2,0-\fullheight/2);
\draw[->,color=black] (0-\fullwidth/2,\fullheight/2) -- (0-\fullwidth/2,0-\fullheight/2);
\end{tikzpictures}
}
\begin{document}
\altframe{i love this sample text}{100}
\end{document}
답변1
나는 당신이 무엇을 하려는지 알 수 없습니다. 그러나 귀하의 하위 질문에 대해서는 다음을 수행하십시오.
Tikz 사진에서 노드의 높이를 계산합니다.
\makeatletter
\newcommand\getheightofnode[2]{%
\pgfextracty{#1}{\pgfpointanchor{#2}{north}}%
\pgfextracty{\pgf@ya}{\pgfpointanchor{#2}{south}}%
\addtolength{#1}{-\pgf@ya}}
\makeatother
길이를 다른 길이로 나누다
당신은 할 수 있고 \usetikzlibrary{math}
간단히 쓸 수 있습니다
\tikzmath{
\numberoflines=\fullwidth/\widthofone;}
그리고 둥글게 말해요
\tikzmath{
\numberoflines=ceil(\fullwidth/\widthofone);}
하지만, 주의해주세요
- 그런 식으로 줄 수를 계산할 수 없습니다. TeX은 줄바꿈하는 경향이 있기 때문에적절한 위치, 일반적으로 줄 수가 더 많습니다.
- '라인의 (전체) 높이'는 상수가 아닙니다. 예를 들어
{x xx}
,{M MM}
, 및{j jj}
의 높이가 다릅니다. - 그리고 더 나쁜 것은 '줄의 (전체) 높이'입니다.단락에서
\settototalheight
'라는 말은 주는 것과 다르다 . 일반적으로 전자는\baselineskip
이지만 더 클 수도 있습니다.
그래서 다음 코드가 귀하의 접근 방식에 더 가깝다고 생각합니다
\documentclass{article}
\usepackage{calc,tikz}\usetikzlibrary{math}
\newlength\widthofone \newlength\fullwidth \newlength\heightoneline \newlength\fullheight
\makeatletter
\newcommand\getheightofnode[2]{%
\pgfextracty{#1}{\pgfpointanchor{#2}{north}}%
\pgfextracty{\pgf@ya}{\pgfpointanchor{#2}{south}}%
\addtolength{#1}{-\pgf@ya}}
\makeatother
\newcommand {\altframe}[2]{
\widthofone=#2
\heightoneline\baselineskip
\settowidth{\fullwidth}{#1}
\begin{tikzpicture}[->,color=black]
\node[text width=#2](baby)at(0,0){#1};
\getheightofnode\fullheight{baby}
\tikzmath{
\numberoflines=round(\fullheight/\heightoneline);}
\draw(\fullwidth/2,\fullheight/2)--(-\fullwidth/2,\fullheight/2);
\draw(\fullwidth/2,-\fullheight/2)--(-\fullwidth/2,-\fullheight/2);
\draw(\fullwidth/2,\fullheight/2)--(\fullwidth/2,-\fullheight/2);
\draw(-\fullwidth/2,\fullheight/2)--(-\fullwidth/2,-\fullheight/2);
\node[text width=5cm]at(0,-3){
widthofone =\the\widthofone \\
fullwidth =\the\fullwidth \\
heightoneline =\the\heightoneline \\
fullheight =\the\fullheight \\
numberoflines = \numberoflines};
\end{tikzpicture}}
\begin{document}
\altframe{i love this sample text}{50pt}
\end{document}