如何从纸张边缘定位图片?

如何从纸张边缘定位图片?

我编写了一个显示我公司徽标的包:

\NeedsTeXFormat{LaTeX2e}[1994/06/01]
\ProvidesPackage{acmelogo}[2022/09/09 ACME Inc. Logo]

\RequirePackage{xcolor}
\RequirePackage{textpos}
\RequirePackage[dvipsnames,x11names]{pstricks}

\def\logotext{ACME Inc.\\A world company that manufactures everything}

\newcommand{\logo}[2]{%
    \begin{pspicture}(#1,-#2)
        \newrgbcolor{curcolor}{0.88 0.15 0.11}
        \psset{
            unit=0.7pt,
            linestyle=none,
            fillstyle=solid,
            fillcolor=curcolor
        }
        \pscustom{
            \newpath
            \moveto(74, 18)
            \lineto(56, 18)
            \lineto(56, 12)
            \lineto(68, 12)
            \lineto(68, 12)
            \curveto(67, 7)(63, 5)(57, 5)
            \curveto(50, 5)(45, 10)(45, 17)
            \curveto(45, 24)(50, 30)(57, 30)
            \curveto(63, 30)(67, 27)(69, 23)
            \lineto(74, 25)
            \curveto(71, 32)(65, 35)(57, 35)
            \curveto(47, 35)(39, 27)(39, 17)
            \curveto(39, 7)(47, 0)(57, 0)
            \curveto(62, 0)(66, 2)(69, 5)
            \lineto(69, 1)
            \lineto(74, 1)
            \lineto(74, 17)
            \lineto(74, 17)
            \lineto(74, 17)
            \closepath
        }
        \pscustom{
            \newpath
            \moveto(27, 61)
            \lineto(5, 61)
            \lineto(5, 75)
            \lineto(0, 75)
            \lineto(0, 42)
            \lineto(5, 42)
            \lineto(5, 56)
            \lineto(27, 56)
            \lineto(27, 42)
            \lineto(33, 42)
            \lineto(33, 75)
            \lineto(27, 75)
            \closepath
        }
    \end{pspicture}
}

目标是在主文档上使用它:

\begin{document}
\logo
% ...
\end{document}

不幸的是,该位置\begin{textblock*}{5cm}(-1cm, 1.7cm)并不是绝对取决于纸张,而是取决于页面的几何形状。

如何才能将该徽标定位在页面的绝对位置?

理想情况下,我想要这样的东西:

\logo[left=1cm,top=1cm]

答案1

使用该tikz包,可以使用绝对页面坐标来定位材料,而不管文本使用的几何形状如何。

只需一行 ( \node at ...) 将徽标图像定位在距离页面右上角左上角一定距离的位置 ( current page.north west),同时在其右侧添加所需的徽标文本 ( label)。

logotext命令允许您定义和格式化徽标文本,而该logoimg命令对实际徽标执行相同的操作。

其中心位置由以下公式获得\placelogo{<left>}{<top>}

A

使用\placelogo{<left>}{<top>}

\documentclass{article}

\usepackage[left=2.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm,showframe]{geometry}

% ********************** added<<<<<<<<<<<<<
\usepackage{tikz}

\newcommand{\logotext}{\sffamily \bfseries \large ACME Inc.\\A world company that manufactures everything}% design the text <<<
\newcommand{\logoimg}{\includegraphics[width=2cm,keepaspectratio]{example-image-a}} % put the real logo

\newcommand{\placelogo}[2]{%
    \begin{tikzpicture}[remember picture,overlay]
        \node at ([xshift=#1, yshift=-#2] current page.north west)
        [label={right:{\parbox{\textwidth}{\logotext}}}]
        {\logoimg};
    \end{tikzpicture}\vspace*{-\baselineskip}}
% **********************

\begin{document}
    
    \placelogo{2cm}{2cm}    

    Some words
    
\end{document}

选项 现在使用pspicture带有徽标和文字的:

d

\documentclass{article}

\usepackage[left=2.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm,showframe]{geometry}

\usepackage{pstricks-add}   

% ********************** added<<<<<<<<<<<<<
\usepackage{tikz}

\newlength{\pssize}\setlength{\pssize}{1cm} % size of the logo image <<<<<<<<<<<<<<
\newcommand{\logotextformat}{\sffamily \bfseries \large} % format of the logo text  <<<<<<<<<<<<<<

\newcommand{\logoimg}[2]{\begin{pspicture}(#1,-#2)      
        \multido{\rA=22.5+45}{8}{
            \rput{\rA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=blue!20](0,0)(0,-\pssize)(0.15,-0.15)}
            \rput{\rA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=blue!10](0,0)(0,-\pssize)(-0.15,-0.15)}
        }           
        \multido{\iA=45+90}{4}{
            \rput{\iA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=blue!50](0,0)(0,-0.8\pssize)(0.1,-0.1)}
            \rput{\iA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=blue!20](0,0)(0,-0.8\pssize)(-0.1,-0.1)}
        }           
        \multido{\iA=0+90}{4}{
            \rput{\iA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=blue](0,0)(0,-0.8\pssize)(0.1,-0.1)}
            \rput{\iA}(-0.1,0.1){\pspolygon[fillstyle=solid,fillcolor=white](0,0)(0,-0.8\pssize)(-0.1,-0.1)}
        }   
        \uput{1.2\pssize}[14](-0.1;0){\logotextformat ACME Inc} 
        \uput{1.2\pssize}[-10](-0.1;0){\logotextformat A world company that manufactures everything}    
\end{pspicture}}    % put the actual logo

\newcommand{\placelogo}[2]{% \logo{<left>}{<top>}
    \begin{tikzpicture}[remember picture,overlay, align=center,]
        \node(logo) at ([xshift=#1, yshift=-#2] current page.north west)
        [anchor=north west] {\logoimg{#1}{#2}};                     
    \end{tikzpicture}\vspace*{-\baselineskip}}
% **********************

\begin{document}
    
    \placelogo{2cm}{2cm}    
    
    Some words
    
\end{document}

徽标图案的灵感来源于“指南针”PStricks 示例

更新在后续问题之后。

pspicture由命令定义\logoimg

用于\placelogo{<left>}{<top>}将其定位在页面的中心。

X

\documentclass{article}

\usepackage[left=2.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm,showframe]{geometry}

\usepackage{pstricks-add}   

% ********************** added<<<<<<<<<<<<<
\usepackage{tikz}

\newlength{\pssize}\setlength{\pssize}{1cm} % size of the logo image <<<<<<<<<<<<<<
\newcommand{\logotextformat}{\sffamily \bfseries \large} % format of the logo text  <<<<<<<<<<<<<<

\newcommand{\logoimg}[2]{% actual logo
    \begin{pspicture}(#1,-#2)
        \newrgbcolor{curcolor}{0.88 0.15 0.11}
        \psset{
            unit=0.7pt,
            linestyle=none,
            fillstyle=solid,
            fillcolor=curcolor
        }
        \pscustom{
            \newpath
            \moveto(74, 18)
            \lineto(56, 18)
            \lineto(56, 12)
            \lineto(68, 12)
            \lineto(68, 12)
            \curveto(67, 7)(63, 5)(57, 5)
            \curveto(50, 5)(45, 10)(45, 17)
            \curveto(45, 24)(50, 30)(57, 30)
            \curveto(63, 30)(67, 27)(69, 23)
            \lineto(74, 25)
            \curveto(71, 32)(65, 35)(57, 35)
            \curveto(47, 35)(39, 27)(39, 17)
            \curveto(39, 7)(47, 0)(57, 0)
            \curveto(62, 0)(66, 2)(69, 5)
            \lineto(69, 1)
            \lineto(74, 1)
            \lineto(74, 17)
            \lineto(74, 17)
            \lineto(74, 17)
            \closepath
        }
        \pscustom{
            \newpath
            \moveto(27, 61)
            \lineto(5, 61)
            \lineto(5, 75)
            \lineto(0, 75)
            \lineto(0, 42)
            \lineto(5, 42)
            \lineto(5, 56)
            \lineto(27, 56)
            \lineto(27, 42)
            \lineto(33, 42)
            \lineto(33, 75)
            \lineto(27, 75)
            \closepath
        }
    \end{pspicture}
}


\newcommand{\placelogo}[2]{% \logo{<left>}{<top>}
    \begin{tikzpicture}[remember picture,overlay, align=center,]
        \node(logo) at ([xshift=#1, yshift=-#2] current page.north west)
        [anchor=north west] {\logoimg{#1}{#2}};                     
    \end{tikzpicture}\vspace*{-\baselineskip}}
% **********************

\begin{document}
    
    \placelogo{2cm}{3cm} 
    
    Some words
    
\end{document}

答案2

运行lualatex

\documentclass{article}

\usepackage[left=2.00cm, right=3.00cm, top=4.00cm, bottom=3.00cm,showframe]{geometry}
\usepackage{pst-abspos,graphicx}

\newcommand\logo[1][]{\pstPutAbs[position=ul](0,0){%
  \tabular{l}\includegraphics[#1]{/tmp/compass}\endtabular
  \sffamily\bfseries\tabular{l}ACME Inc\\A world company that manufactures everything\endtabular}}

\begin{document}
\pstSetAbsoluteOrigin\logo[width=2cm]%
Some words
    
\end{document}

在此处输入图片描述

答案3

使用eso-pic您可以将内容绝对地放置在页面上。以下为命令添加了一个键值left选项:top\logo

在此处输入图片描述

\documentclass{article}

\usepackage{xcolor,eso-pic,xkeyval}
\usepackage[dvipsnames,x11names]{pstricks}

\makeatletter
\define@cmdkey{logokeys}[logokeys@]{left}[0pt]{}% left key (default 0pt)
\define@cmdkey{logokeys}[logokeys@]{top}[0pt]{}% top key (default 0pt)

\newcommand{\logo}[1][]{%
  \setkeys{logokeys}{left,top,#1}%
  \AddToShipoutPictureFG*{%
    \AtPageUpperLeft{%
      \hspace*{\logokeys@left}%
      \raisebox{-\logokeys@top}{\raisebox{-\height}{%
        \begin{pspicture}(51.8pt,52.5pt)
          \newrgbcolor{curcolor}{0.88 0.15 0.11}
          \psset{
            unit=0.7pt,
            linestyle=none,
            fillstyle=solid,
            fillcolor=curcolor
          }
          \pscustom{
            \newpath
            \moveto(74, 18)
            \lineto(56, 18)
            \lineto(56, 12)
            \lineto(68, 12)
            \lineto(68, 12)
            \curveto(67, 7)(63, 5)(57, 5)
            \curveto(50, 5)(45, 10)(45, 17)
            \curveto(45, 24)(50, 30)(57, 30)
            \curveto(63, 30)(67, 27)(69, 23)
            \lineto(74, 25)
            \curveto(71, 32)(65, 35)(57, 35)
            \curveto(47, 35)(39, 27)(39, 17)
            \curveto(39, 7)(47, 0)(57, 0)
            \curveto(62, 0)(66, 2)(69, 5)
            \lineto(69, 1)
            \lineto(74, 1)
            \lineto(74, 17)
            \lineto(74, 17)
            \lineto(74, 17)
            \closepath
          }
          \pscustom{
            \newpath
            \moveto(27, 61)
            \lineto(5, 61)
            \lineto(5, 75)
            \lineto(0, 75)
            \lineto(0, 42)
            \lineto(5, 42)
            \lineto(5, 56)
            \lineto(27, 56)
            \lineto(27, 42)
            \lineto(33, 42)
            \lineto(33, 75)
            \lineto(27, 75)
            \closepath
          }
        \end{pspicture}
      }}%
    }
  }
}

\usepackage{showframe}

\begin{document}

\logo[left=1cm,top=1cm]

Something

\end{document}

答案4

如果使用该[absolute]选项加载 textpos,则文本块的位置将相对于页面的左上角给出,而不是相对于文本块自然出现的位置。

相关内容