길이를 특정 글꼴의 줄 높이로 설정

길이를 특정 글꼴의 줄 높이로 설정

다음을 사용하여 새 길이를 정의하는 방법:

\newlength{...}
\setlength{...}{...}

특정 글꼴의 줄 높이와 동일합니다(예 \tiny\ttfamily: ).

참고: 저는 해당 부분에 아무것도 쓰지 않는 솔루션을 원합니다 \begin{document}\end{document}.

답변1

이것은 모든 문자(0에서 255까지)에서 반복되므로 pdflatex; XeLaTeX 또는 LuaLaTeX에는 몇 가지 다른 경험적 방법이 필요합니다 fontspec.

디센더를 무시하고 높이만 측정하는 -variant를 사용 하지 않는 한 길이 \fonttotalheight는 높이에 깊이를 더한 것으로 정의됩니다 .*

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}

\newlength{\fonttotalheight}

\makeatletter
\newcommand{\setfonttotalheight}{%
  \@ifstar{\@tempswafalse\setfont@totalheight}%
          {\@tempswatrue\setfont@totalheight}%
}
\newcommand{\setfont@totalheight}[1][]{%
  \sbox{\z@}{%
    \normalfont
    #1% it should be a font selection command
    \selectfont 
    \count@=\z@
    \loop
      \char\count@
    \ifnum\count@<\@cclv
      \advance\count@\@ne
    \repeat
  }%
  \setlength\fonttotalheight{\ht\z@}%
  \if@tempswa\addtolength\fonttotalheight{\dp\z@}\fi
 }
\makeatother

\setfonttotalheight*

\begin{document}

Initial value: \texttt{\the\fonttotalheight} (only height)

\bigskip

\begingroup
Fontencoding: OT1
\fontencoding{OT1}\selectfont

\setfonttotalheight*
Normal font (only height): \texttt{\the\fonttotalheight}

\setfonttotalheight
Normal font (height and depth): \texttt{\the\fonttotalheight}

\setfonttotalheight[\ttfamily]
Typewriter type (height and depth): \texttt{\the\fonttotalheight}

\endgroup

\bigskip

Fontencoding: T1

\setfonttotalheight*
Normal font (only height): \texttt{\the\fonttotalheight}

\setfonttotalheight
Normal font (height and depth): \texttt{\the\fonttotalheight}

\setfonttotalheight[\ttfamily]
Typewriter type (height and depth): \texttt{\the\fonttotalheight}

\end{document}

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

답변2

나는 \totalheightof명령을 시도하고 길이 정의와 해당 설정을 명령으로 래핑했습니다. 이것이 도움이 되기를 바랍니다!

\documentclass[12pt]{scrbook}
\usepackage{etoolbox}
\usepackage{ifmtarg}
\usepackage{calc}

\def\FontHeightDummyText{ABBAASAADSDAgss,qppptssdfaf23l4j324jl234jklsjdflsdkfjslakfjslfsdajfdsljfslkdfjl23k42j34}


\makeatletter
\providecommand{\ProvideLength}[2][]{%
% Check, if the command is already defined, if not, then define it!
\ifdeflength{#2}{% It is already defined!
\GenericWarning{}{Warning: Length #2 already defined!!!!!!!!} % Optional
}{% Not defined, so define it!
\newlength{#2}%
}%
\@ifmtarg{#1}{%  is 1st argument empty -> do not set the length at all!
}{% Set the length to the value of the 1st argument.
\setlength{#2}{#1}%  
}% End of \@ifmtarg
}% End of \providecommand
\makeatother


% Setting the length as 1st parameter and initialize it
% with the value of the second arg. (hopefully a length ;-))
\newrobustcmd{\SetHeightFromTextTemplate}[2]{%
\ProvideLength[\totalheightof{#2}]{#1}%
}%

%\SetHeightFromTextTemplate{} can be done here also

\begin{document}
\begin{flushleft}

\SetHeightFromTextTemplate{\FontHeight}{\FontHeightDummyText}
Height of font is \the\FontHeight 

Using \(\backslash\)Large \Large
%%% Recalculate
\SetHeightFromTextTemplate{\FontHeight}{\FontHeightDummyText}
%\setlength{\FontHeight}{\totalheightof{\FontHeightDummyText}}

Height of font is \the\FontHeight 



Now with \begin{verbatim}\tiny\ttfamily:\end{verbatim} 

\begingroup
\tiny\ttfamily
%%% Recalculate
\SetHeightFromTextTemplate{\FontHeight}{\FontHeightDummyText}


Height of font is \the\FontHeight
\endgroup

\end{flushleft}

\end{document}

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

관련 정보