如何使文字和图片水平和垂直对齐?

如何使文字和图片水平和垂直对齐?

我想根据文本区域水平和垂直对齐文本和图片。到目前为止,我已经尝试使用 TikZ。我设法在任一方向上获得了项目的效果对齐,但不能同时在两个方向上获得效果对齐。

具体来说,我想按照以下规则对齐我的项目:

  • 文字与图片应按其上端垂直对齐。

  • 每项内容都应位于文本区域的边界。就我而言(参见 MWE),目前情况是文本在左侧,图片在右侧。:)

最重要的一点:解决方案不应直接基于图片的测量值,这意味着实施偏移1cm对于其他人来说没有太大帮助……我认为。

问题图片及解释

在此处输入图片描述

图片的 MWE(三角形)

\documentclass[
]
{standalone}

\usepackage{
    tikz,
}

\begin{document}
\begin{tikzpicture}
\draw
(0,0) coordinate (A)
(1,0) coordinate (B)
(1,-1) coordinate (C)
;
\filldraw (A) -- (B) -- (C);
\end{tikzpicture}
\end{document}

实际 MWE 代码

\documentclass[
11pt,
a4paper
]
{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}

\renewcommand{\familydefault}{\sfdefault}

\usepackage{
tikz,
}

\usepackage[
showframe,
]{geometry}


\begin{document}
%Text and picture (triangle) in tikzpicture
\noindent Text and picture (triangle) in tikzpicture:
\begin{flushleft}
\begin{tikzpicture}[
remember picture=true,
overlay,
]
\node (WordThingOne) {\Large
Word};
\node[
anchor=north west,
%xshift=???,
] (PicThingOne) at (WordThingOne.north east) {\includegraphics{picture.pdf}};
\end{tikzpicture}
\end{flushleft}
\vspace{2cm}
%seperate version 1: only picture (triangle) in tikzpicture-node
only picture (triangle) in tikzpicture-node:
\begin{flushright}\Large
Word\hfill%
\begin{tikzpicture}[
remember picture=true,
overlay,
]
\node[
anchor=north west,
%yshift=???,
] (PicThing)  {\includegraphics{picture.pdf}};
\end{tikzpicture}
\end{flushright}
%seperate version 2: \hfill used to seperate the items, no tikzpicture
\verb|\hfill| used to seperate the items, no tikzpicture
\begin{flushright}\Large
Word\hfill%
\includegraphics{picture.pdf}
\end{flushright}
%test for \hfill and right border
test for \verb+\hfill+ and right border:\\
A\hfill B
\end{document}

答案1

这就是您想要实现的吗?

对齐 tikz

\documentclass[11pt,a4paper]{scrartcl}

\usepackage[T1]{fontenc}% unused, not needed
\usepackage[utf8]{inputenc}
\usepackage{tgheros}

\renewcommand{\familydefault}{\sfdefault}

\usepackage{tikzpagenodes}

\begin{document}
\begin{flushleft}
\rule{\textwidth}{1pt}\newline% check alignment
\begin{tikzpicture}[remember picture]
\node[inner sep=0pt] (WordThingOne) {\Large Word};
\end{tikzpicture}

\begin{tikzpicture}[remember picture,overlay]
\node[below left, inner sep=0pt] (PicThingOne)
  at (WordThingOne.north -| current page text area.east)
  {\includegraphics{picture.pdf}};
\end{tikzpicture}
\end{flushleft}
\end{document}

答案2

尝试这个代码可能会有帮助

\documentclass[
11pt,
a4paper
]
{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{tgheros}

\renewcommand{\familydefault}{\sfdefault}

\usepackage{
tikz,
}


\begin{document}
\noindent {\Large Hellow}
\hrulefill%\hfill
\parbox[c][1cm][t]{1cm}{%
\begin{tikzpicture}
\draw
(0,0) coordinate (A)
(1,0) coordinate (B)
(1,-1) coordinate (C)
;
\filldraw (A) -- (B) -- (C);
\end{tikzpicture}
}

\vspace{2cm}
\noindent {\Large Word} 
\hrulefill%\hfill
\parbox[t][1cm][t]{1cm}{%
\begin{tikzpicture}
\draw
(0,0) coordinate (A)
(1,0) coordinate (B)
(1,-1) coordinate (C)
;
\filldraw (A) -- (B) -- (C);
\end{tikzpicture}
}



\end{document}

在此处输入图片描述

相关内容