
잘라내야 할 이미지도 있고 잘라야 할 이미지도 있습니다. 작동하는 두 가지를 사용하여 단일 솔루션을 구현했지만 \newcommand
작동하지 않는 xparse를 사용하는 하나의 컴팩트 솔루션을 찾았는데 그 이유를 이해할 수 없습니다.
아래 코드를 수정하고 개선하는 데 도움을 주시면 감사하겠습니다.
\documentclass[11pt]{article}
\usepackage{easyfig}
% [cut up]{file}{caption}{label}{scale} - Cut up % <== Ok
\newcommand{\ruleone}[5][.05]{%
\Figure[trim={.0\width} {.0\height} {.0\width} {#1\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut down]{file}{caption}{label}{scale} - Cut down % <== Ok
\newcommand{\ruletwo}[5][.05]{%
\Figure[trim={.0\width} {#1\height} {.0\width} {.0\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut up]{file}[cut down]{caption}{label}[scale] - Cut down % <== compile with errors
\newcommand{\onerule}[ o m o m m o ]{%
\Figure[trim={.0\width} {ifNoValueTF{#1}{.0}{#1}\height}%
{.0\width} {ifNoValueTF{#3}{.0}{#3}\height},clip,%
width={ifNoValueTF{#6}{1}{#6}\linewidth},keepaspectratio=true,%
caption={#4},label={#5},center,here]{#2}
}
\begin{document}
Here comes the images:
\ruleone[.45]{example-image-a}{First image}{label1}{.5} % <== this works
\ruletwo[.35]{example-image-a}{Second image}{label2}{.5} % <== This too
\onerule[.35]{example-image-b}{Third image}{label3}{.5}
\onerule{example-image-b}[0.45]{Third image}{label3}{.5}
\end{document}
답변1
에서는 xparse
새 명령을 정의하는 명령이 \NewDocumentCommand
대신 사용됩니다 \newcommand
. 또한 매개변수를 설명하는 두 번째 인수는 필수( {...}
대신 [...]
)이며 (대문자 및 백슬래시 포함) ifNoValueTF
이어야 합니다 .\IfNoValueTF
또한 %
트림 인수가 있는 줄 끝에는 필수 공백이 표시되지 않으며 scale 인수는 선택 사항입니다( [...]
대신 {...}
).
그러면 당신은 얻습니다
\documentclass[11pt]{article}
\usepackage{xparse,easyfig}
% [cut up]{file}{caption}{label}{scale} - Cut up % <== Ok
\newcommand{\ruleone}[5][.05]{%
\Figure[trim={.0\width} {.0\height} {.0\width} {#1\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut down]{file}{caption}{label}{scale} - Cut down % <== Ok
\newcommand{\ruletwo}[5][.05]{%
\Figure[trim={.0\width} {#1\height} {.0\width} {.0\height},clip,%
width=#5\linewidth,keepaspectratio=true,%
caption={#3},label={#4},center,here]{#2}
}
% [cut up]{file}[cut down]{caption}{label}[scale] - Cut down % <== compile with errors
\NewDocumentCommand \onerule { o m o m m o }{%
\Figure[trim={.0\width} {\IfNoValueTF{#1}{.0}{#1}\height}
{.0\width} {\IfNoValueTF{#3}{.0}{#3}\height},clip,%
width={\IfNoValueTF{#6}{1}{#6}\linewidth},keepaspectratio=true,%
caption={#4},label={#5},center,here]{#2}
}
\begin{document}
Here comes the images:
\ruleone[.45]{example-image-a}{First image}{label1}{.5} % <== this works
\ruletwo[.35]{example-image-a}{Second image}{label2}{.5} % <== This too
\onerule[.35]{example-image-b}{Third image}{label3}[.5]
\onerule{example-image-b}[0.45]{Third image}{label3}[.5]
\end{document}