eso-pic 與 bidi 一起

eso-pic 與 bidi 一起

我建立了一個文檔類,它使用該eso-pic套件將內容放置在相對於左上角的每個頁面上。現在我在(部分)希伯來文的文檔中使用了這個文檔類別。對於希伯來語,我正在使用polyglossia包,根據這個帖子與 XeLaTeX 一起使用。用於polyglossiabidi頁面佈局切換為從右到左。

除了左上角的定位之外,一切都正常運作。以下範例顯示了我的問題:

\documentclass{article}

% set font for hebrew
\usepackage{fontspec}
\setmainfont{DejaVuSans.ttf}

% if polyglossia is commented
\providecommand{\setLTR}{}
\providecommand{\setRTL}{}

% write "test" a few times
\newcounter{loopcounter}
\newcommand{\writetest}{
    \loop
    \ifnum\value{loopcounter}<36
        Test\theloopcounter 
        \stepcounter{loopcounter}
    \repeat
}

% add the test in the top left corner
\usepackage{calc}
\usepackage{picture}
\usepackage{eso-pic}
\AddToShipoutPictureFG{
    \AtPageUpperLeft{%
        % see the bottom of the question for the \put()
        \put(0,0){
            \raisebox{-\height-3pt}{
                % needed to do left to right align and for breaking
                \parbox{\paperwidth}{
                    \setLTR
                    \writetest
                }
            }
        }
    }
}

\usepackage{polyglossia} % <- If those packages are commented the placing
\setmainlanguage{hebrew} % <- of the top left content is correct.

\begin{document}
    תוכן
\end{document}

如果我編譯給定的範例,我會得到下圖底部所示的結果。但是放置在左上角的內容並不在左上角。

上面第二張圖片是完全相同的範例,但\usepackage{polyglossia}\setmainlanguage{hebrew}已註記。所以bidi包沒有被載入。角落的文字是正確的。但現在希伯來文本(當然)不是從右到左。

在此輸入影像描述

正如您在我提供的程式碼中看到的,我已經嘗試使用\put()(與picture套件一起)來修復偏移量。但我不知道它是什麼。它應該是類似的東西-\textwidth-\marginright。但事實並非如此。

請注意,它\AddToShipoutPictureFG位於文件類別中。它與內容不在同一文件中。我想在各種文件中使用文檔類,以便尺寸發生變化。我必須知道相對於頁面尺寸的偏移量。不是絕對值。使用put(-11.872cm, 0)並不能解決我的問題。

polyglossiaeso-pic左上角放置內容如何搭配使用?

答案1

儘管不是您所希望的,但這裡有一個使用background套件 和可以輕鬆實現的解決方案tikz

\documentclass[letterpaper]{article}

% set font for hebrew
\usepackage{fontspec}
\setmainfont{DejaVuSans.ttf}

% write "test" a few times
\newcounter{loopcounter}
\newcommand{\writetest}{
    \loop
    \ifnum\value{loopcounter}<36
        Test\theloopcounter 
        \stepcounter{loopcounter}
    \repeat
}

% add the test in the top left corner
\usepackage[all]{background}
\backgroundsetup{%
  placement = top,
  color = black,
  opacity=1,
  scale = 1,
  vshift=-6pt,
  contents = {%
    \tikz \node [text width=\paperwidth-12pt, align=justify] {\writetest};
  },
}

\usepackage{polyglossia}
\setmainlanguage{hebrew}

\begin{document}
    תוכן
\end{document}

輸出

相關內容