我编写了一个个人命令,允许您将文本放在图形旁边。此宏已针对与此处的 tikz calc 库的不兼容性进行了更正:个人命令与 tikz calc 库不兼容
但是,这种修正会导致法语中的印刷间距错误,而这两个字符恰恰导致了 tikz calc 库出现问题。以下是屏幕截图:
双点“:”后面的细空格或感叹号“!”后面的细空格(第一行是正确的)在第二行消失了。
\documentclass{article}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{babel}
\newlength{\colG}\newlength{\colD}
% Wrapper command just changes catcodes and calls helper
\newcommand\compo{%
\shorthandoff{!:}% Change the catcodes
\compohelper % call helper to grab arguments
}
\newcommand{\compohelper}[3][0.5]{% do actual work
\setlength{\colG}{#1\linewidth}%
\setlength{\colD}{\linewidth}%
\addtolength{\colD}{-\colG}%
\addtolength{\colG}{-10pt}%
\addtolength{\colD}{-10pt}%
\par \noindent%
\begin{minipage}[t]{\colG}#2\end{minipage}\hfill\vrule\hfill%
\begin{minipage}[t]{\colD}#3\end{minipage}%
\par
\shorthandon{!:}% restore catcodes
}
\begin{document}
Car: En effet!
\dotfill
\bigskip
\compo[.5]{
Car: En effet!
}{
\begin{tikzpicture}
\coordinate (B) at (0,0);
\coordinate (C) at (3,0);
\coordinate(D) at (2,0);
\draw(B)--(C)--(D)--cycle;
\coordinate (Ap) at ($(C)!.35!-90:(B)$);
\draw (Ap)--(B)--(C)--cycle;
\end{tikzpicture}
}
\end{document}
是否可以允许 tikz 和 babel french 在此宏上并行使用,以便印刷空间符合法语?
答案1
使用环境:
\documentclass{article}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{babel}
\newlength{\colG}\newlength{\colD}
\newenvironment{compo}[1][0.5]
{%
\setlength{\colG}{#1\linewidth}%
\setlength{\colD}{\linewidth}%
\addtolength{\colD}{-\colG}%
\addtolength{\colG}{-10pt}%
\addtolength{\colD}{-10pt}%
\par\noindent
\begin{minipage}[t]{\colG}%
}
{%
\end{minipage}%
\par
}
\newcommand{\compobreak}{%
\end{minipage}\hfill\vrule\hfill
\begin{minipage}[t]{\colD}%
}
\begin{document}
Car: En effet!
\dotfill
\bigskip
\begin{compo}[.5]
Car: En effet!
\compobreak
\begin{tikzpicture}
\coordinate (B) at (0,0);
\coordinate (C) at (3,0);
\coordinate(D) at (2,0);
\draw(B)--(C)--(D)--cycle;
\coordinate (Ap) at ($(C)!.35!-90:(B)$);
\draw (Ap)--(B)--(C)--cycle;
\end{tikzpicture}
\end{compo}
\begin{compo}[.5]
\begin{tikzpicture}
\coordinate (B) at (0,0);
\coordinate (C) at (3,0);
\coordinate(D) at (2,0);
\draw(B)--(C)--(D)--cycle;
\coordinate (Ap) at ($(C)!.35!-90:(B)$);
\draw (Ap)--(B)--(C)--cycle;
\end{tikzpicture}
\compobreak
Car: En effet!
\end{compo}
\end{document}
答案2
只需使用原始 catcodes 抓住第一个参数。
\documentclass{article}
\usepackage[french]{babel}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{babel}
\newlength{\colG}\newlength{\colD}
% Wrapper command just changes catcodes and calls helper
\newcommand\compo[2][0.5]{%
\shorthandoff{!:}% Change the catcodes
\compohelper[#1]{#2} % call helper to grab arguments
}
\newcommand{\compohelper}[3][0.5]{% do actual work
\setlength{\colG}{#1\linewidth}%
\setlength{\colD}{\linewidth}%
\addtolength{\colD}{-\colG}%
\addtolength{\colG}{-10pt}%
\addtolength{\colD}{-10pt}%
\par \noindent%
\begin{minipage}[t]{\colG}#2\end{minipage}\hfill\vrule\hfill%
\begin{minipage}[t]{\colD}#3\end{minipage}%
\par
\shorthandon{!:}% restore catcodes
}
\begin{document}
Car: En effet!
\dotfill
\bigskip
\compo[.5]{
Car: En effet!
}{
\begin{tikzpicture}
\coordinate (B) at (0,0);
\coordinate (C) at (3,0);
\coordinate(D) at (2,0);
\draw(B)--(C)--(D)--cycle;
\coordinate (Ap) at ($(C)!.35!-90:(B)$);
\draw (Ap)--(B)--(C)--cycle;
\end{tikzpicture}
}
\end{document}