Beamer、philex 和 \hfill

Beamer、philex 和 \hfill

我使用該套件philex作為語言範例,並嘗試將文字元素放在行尾(右居中)。我嘗試使用該\hfill命令,但正如 MWE 將向您展示的那樣,它不提供連貫的對齊。

\documentclass[12pt]{beamer}
\usepackage[francais]{babel}
\usepackage{philex}

\begin{document}

\begin{frame}{The syntactic ambiguity}
    \lb{}{
        \lba{}{Fred eats an apple. \hfill (a)}
        \lbz{}{Fred eats an apple. \hfill (a)}  
    }
\end{frame}

\end{document}

有人可以幫我解決這個奇怪的行為嗎?

答案1

您應該避免,philex因為egreg在他的回答中給出了原因。用於排版語言範例的最常用套件是gb4e,expex, 和linguex(這是由加載philex)。看Alan Munn 對這些軟體套件的精彩比較更多細節。philex新增的許多功能linguex(交叉引用、重複範例、標籤自訂等)都可以在expex.

所有這些包都允許您擁有右對齊的註釋。看以下問題的答案用語言訊息標記語言範例用於說明如何在每個套件中執行此操作的程式碼。expex是唯一為這些右對齊註釋提供本機命令的命令:\rightcomment

答案2

原因是該philex套件的編寫方式很糟糕,並且不保護定義中的行尾。你所看到的空間主要是由這些未受保護的空間所造成的。

在 \newcommand 或類似命令的行尾添加百分比字元何時有害了解更多。

它們有太多未受保護的行尾,無法提出修復方案;還有一個問題是巨集定義非常大且沒有使用模組化。

您可以透過使用瘋狂的黑客手段來「解決」該問題;然而,如果在定義的某個點確實需要空格,這可能會產生意想不到的結果。

\documentclass{article}
\usepackage{showframe}

\endlinechar=-1
\usepackage{philex}
\endlinechar=13

\begin{document}

\lb{y}{%
   \lba{y1}{Fred eats an apple. \hfill (a)}%
   \lbz{y2}{Fred eats an apple. \hfill (a)}%
}

\end{document}

請注意,輸入中的行尾也必須受到保護。該showframe包僅用於演示與邊距的對齊。

在此輸入影像描述

真正的解決方法是不使用該套件並要求其維護者糾正錯誤的程式碼。

\lb只是為了展示一個例子,這裡是(為了方便而添加的行號)的定義

 95 \newcommand{\lb}[3][n]{
 96 \ifdim\lastskip=\Extopsep\vspace\Exredux\else \fi
 97 \immediate\write\@auxout{\unexpanded{\expandafter\gdef\csname#2r\endcsname{#3}\expandafter\gdef\csname#2\endcsname{\ref{#2}}
 98 \expandafter\gdef\csname#2p\endcsname{\MakeLowercase#3}}}
 99 \expandafter\providecommand\expandafter{\csname#2r\endcsname}{#3}
100 \expandafter\providecommand\expandafter{\csname#2\endcsname}{\ref{#2}}\expandafter\providecommand\expandafter{\csname#2p\endcsname}{\MakeLowercase#3}
101 \ifhyperref%
102 \renewcommand{\theFnExNo}{\roman{FnExNo}}
103 \ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}
104 \setlength{\belowdisplayskip}{2ex}%
105 \parbox{\centro}{\centering \hypertarget{#2}{#3}\philpunct}\else \hypertarget{#2}{#3}\philpunct\fi\par
106 \else 
107 \ex. \label{#2} \if#1c \setlength{\abovedisplayskip}{1ex}\setlength{\belowdisplayskip}{2ex}%
108 \parbox{\centro}{\centering #3\philpunct}\else #3\philpunct\fi\par%
109 \fi}

%第 95、97、98、99、100、102 和 103 行末尾%缺少。唯一正確放置的%字元位於第 104 行和第 107 行的末尾。

的定義\lba也同樣有缺陷。

相關內容