对齐偏移文本和边距注释

对齐偏移文本和边距注释

我正在创建一些带有右对齐边距注释的文本,并且我想使左边距空间与右边距空间相同。

我的对齐想法:

设置\pageLeftMargin\pageRightMargin++\marginNoteLength\myMarginparSep

\newlength{\marginNoteLength}
\settowidth{\marginNoteLength}{1903 - 1908}

\newcommand{\myMarginparSep}{20pt}
\newcommand{\pageRightMargin}{0in}

\newlength{\pageLeftMargin}
\setlength{\pageLeftMargin}{\dimexpr(\pageRightMargin+\marginNoteLength+\myMarginparSep)\relax}

\newlength{\marginoffset}
\setlength{\marginoffset}{\dimexpr(\pageLeftMargin-\pageRightMargin)\relax}

\geometry{
    left=\pageLeftMargin,
    top=1in,
    right=\pageRightMargin,
    bottom=1in,
    marginparsep=\myMarginparSep,
    marginparwidth=10in,
}

但事实证明,它不起作用:右边距为零,而左边距不为零。

我如何解决它?

在此处输入图片描述

%!TEX TS-program = lualatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article}

% DOCUMENT LAYOUT
\usepackage{enumitem, geometry, calc}

\newlength{\marginNoteLength}
\settowidth{\marginNoteLength}{1903 - 1908}

\newcommand{\myMarginparSep}{20pt}
\newcommand{\pageRightMargin}{0in}

\newlength{\pageLeftMargin}
\setlength{\pageLeftMargin}{\dimexpr(\pageRightMargin+\marginNoteLength+\myMarginparSep)\relax}

\newlength{\marginoffset}
\setlength{\marginoffset}{\dimexpr(\pageLeftMargin-\pageRightMargin)\relax}

\geometry{
    left=\pageLeftMargin,
    top=1in,
    right=\pageRightMargin,
    bottom=1in,
    marginparsep=\myMarginparSep,
    marginparwidth=10in,
}

\usepackage{luatexja-fontspec}
\setmainfont[Numbers=OldStyle]{Linux Libertine}

\usepackage{marginnote}
\newcommand{\marginNote}[1]{\mbox{}\marginnote{\hfill \normalsize #1}}
\renewcommand*{\raggedleftmarginnote}{}
\reversemarginpar

\begin{document}
\centerline{\tikz{\draw[-] (0,0)--(29.9,0);
    \foreach \i in {0,0.1,...,29.8}{\node (\i) at (\i,0) {$|$};}
    }
}
\marginNote{1908 - 1911} \hfill University of Bern\\
\marginNote{1911 - 1912} \hfill University of Zürich\\
\marginNote{1912 - 1914} \hfill Charles University of Prague\\
\marginNote{1914 - 1932} \hfill Prussian Academy of Sciences, Berlin\\
\marginNote{1920 - 1930} \hfill University of Leiden\\
\marginNote{1932 - 1955} \hfill Institute for Advanced Study, Princeton

\end{document}

答案1

我正在尝试理解/重现您的问题。当我使用一个额外的水平线运行您的代码时,

\documentclass[10pt]{article}

\usepackage{geometry,lipsum}
\usepackage{calc}
\usepackage{tikz}

\newlength{\marginNoteLength}
\settowidth{\marginNoteLength}{random marginnote}

\newcommand{\myMarginparSep}{20pt}
\newcommand{\pageRightMargin}{1.1in}

\newlength{\pageLeftMargin}
\setlength{\pageLeftMargin}{\dimexpr(\pageRightMargin+\marginNoteLength+\myMarginparSep)\relax}

\geometry{
    left=\pageLeftMargin,
    top=1in,
    right=\pageRightMargin,
    bottom=1in,
    marginparsep=\myMarginparSep,
    marginparwidth=10in,
}

\usepackage{marginnote}
\newcommand{\marginNote}[1]{\mbox{}\marginnote{\hfill \normalsize #1}}
\renewcommand*{\raggedleftmarginnote}{}
\reversemarginpar

\thispagestyle{empty}
\setlength\parindent{0in}
\begin{document}
\centerline{\tikz{\draw[-] (0,0)--(29.9,0);
\foreach \i in {0,0.1,...,29.8}{\node (\i) at (\i,0) {$|$};}
\foreach \i in {0,1,...,29}{\node (\i) at (\i,0) {\Huge$|$};}}}

\marginNote{random marginnote}\lipsum[1-1]
{\vspace*{5pt}}
\marginNote{random marginnote}\lipsum[1-1]
{\vspace*{5pt}}
\marginNote{random marginnote}\lipsum[1-1]

\end{document}

我明白了

在此处输入图片描述

你能告诉我哪个距离不一致吗?

答案2

发现问题:

\marginNoteLength在设置字体之前进行了计算。我应该在设置字体之后进行计算。

Length of 1234567890 before font setting: 50.00015pt
Length of 1234567890 after font setting:  46.48438pt

在此处输入图片描述

%!TEX TS-program = lualatex
%!TEX encoding = UTF-8 Unicode

\documentclass[10pt]{article}

% DOCUMENT LAYOUT
\usepackage{enumitem, geometry, calc, tikz}

\newlength{\lenBeforeFontSetting}
\settowidth{\lenBeforeFontSetting}{1234567890}

\usepackage{luatexja-fontspec}
\setmainfont[Numbers=OldStyle]{Linux Libertine}

\newlength{\marginNoteLength}
\settowidth{\marginNoteLength}{1903 - 1908}

\newcommand{\myMarginparSep}{20pt}
\newcommand{\pageRightMargin}{0in}

\newlength{\pageLeftMargin}
\setlength{\pageLeftMargin}{\dimexpr(\pageRightMargin+\marginNoteLength+\myMarginparSep)\relax}

\newlength{\marginoffset}
\setlength{\marginoffset}{\dimexpr(\pageLeftMargin-\pageRightMargin)\relax}

\geometry{
    left=\pageLeftMargin,
    top=1in,
    right=\pageRightMargin,
    bottom=1in,
    marginparsep=\myMarginparSep,
    marginparwidth=10in,
}


\newlength{\lenAfterFontSetting}
\settowidth{\lenAfterFontSetting}{1234567890}

\usepackage{marginnote}
\newcommand{\marginNote}[1]{\mbox{}\marginnote{\hfill \normalsize #1}}
\renewcommand*{\raggedleftmarginnote}{}
\reversemarginpar

\setlength\parindent{0in}

\begin{document}

\centerline{\tikz{\draw[-] (0,0)--(29.9,0);
    \foreach \i in {0,0.1,...,29.8}{\node (\i) at (\i,0) {$|$};}
    }
}

\marginNote{1908 - 1911} \hfill University of Bern\\
\marginNote{1911 - 1912} \hfill University of Zürich\\
\marginNote{1912 - 1914} \hfill Charles University of Prague\\
\marginNote{1914 - 1932} \hfill Prussian Academy of Sciences, Berlin\\
\marginNote{1920 - 1930} \hfill University of Leiden\\
\marginNote{1932 - 1955} \hfill Institute for Advanced Study, Princeton

\vspace*{30pt}

Length of 1234567890 before font setting: \the\lenBeforeFontSetting\\
Length of 1234567890 after font setting: \the\lenAfterFontSetting

\end{document}

相关内容