scrlttr2:如何将 firsthead 与页面右边缘左对齐?

scrlttr2:如何将 firsthead 与页面右边缘左对齐?

假设我们有这个最小工作示例(MWE)

\documentclass[english]{scrlttr2}

\usepackage{babel}

\newkomavar{fromplace}
\setkomavar{fromname}{Alice Alison}
\setkomavar{fromaddress}{Fairytail-Lane 1}
\setkomavar{fromplace}{12345 Cologne}

\setkomavar{firsthead}{%
    \parbox{\textwidth}{%
        \raggedleft
        {\usekomafont{fromname}\strut\ignorespaces{\usekomavar{fromname}\\\usekomavar{fromaddress}\\\usekomavar{fromplace}}}\\
    }
}

% \KOMAoptions{refline=dateleft} <--- To move the date to the left edge

\begin{document}

    \begin{letter}{Bob Bobson\\40 Michigan Street\\US-1234 Oklahoma}

        \opening{Hello Bob,}

        \closing{Best wishes}

    \end{letter}

\end{document}

结果截图:

结果截图


问题说明:

我怎样才能将 左对齐firsthead到页面右边缘?date也是左对齐的,所以它无论如何都应该可以工作。:-)

所需状态的屏幕截图

答案1

您可以在 中使用表格\firsthead。我使用数组来访问固定宽度的w-column,但您也可以使用 -column p。此外,您可以使用以下方法计算列的宽度,\dimexpr而不是对宽度进行硬编码:

示例 1

在此处输入图片描述

\documentclass[english]{scrlttr2}

\usepackage{babel, array}

\newkomavar{fromplace}
\setkomavar{fromname}{Alice Alison}
\setkomavar{fromaddress}{Fairytail-Lane 1}
\setkomavar{fromplace}{12345 Cologne}

\setkomavar{firsthead}{%
        \begin{tabular*}{\linewidth}{wl{13cm}l}
           &\usekomafont{fromname}\strut\ignorespaces{\usekomavar{fromname}}\\
           &\usekomavar{fromaddress}\\
           &\usekomavar{fromplace}\\
         \end{tabular*}
    }


% \KOMAoptions{refline=dateleft} <--- To move the date to the left edge

\begin{document}

    \begin{letter}{Bob Bobson\\40 Michigan Street\\US-1234 Oklahoma}

        \opening{Hello Bob,}

        \closing{Best wishes}

    \end{letter}

\end{document}

示例 2:

您也可以修改代码。只需使用更窄的\parbox,将其内容左对齐,将 右对齐即可\parbox

\documentclass[english]{scrlttr2}

\usepackage{babel}

\newkomavar{fromplace}
\setkomavar{fromname}{Alice Alison}
\setkomavar{fromaddress}{Fairytail-Lane 1}
\setkomavar{fromplace}{12345 Cologne}

\setkomavar{firsthead}{%
    \raggedleft\parbox{0.2\textwidth}{%           %% Move the `\parbox` to the right margin and limit its width to the content
        \raggedright                              %% Left align the content
        {\usekomafont{fromname}\strut\ignorespaces{\usekomavar{fromname}\\\usekomavar{fromaddress}\\\usekomavar{fromplace}}}\\
    }
}

% \KOMAoptions{refline=dateleft} <--- To move the date to the left edge

\begin{document}

    \begin{letter}{Bob Bobson\\40 Michigan Street\\US-1234 Oklahoma}

        \opening{Hello Bob,}

        \closing{Best wishes}

    \end{letter}

\end{document}

相关内容