0

I'd like to align text and a picture horizontally as well as vertically, based on the text area. So far I have tried using TikZ. I managed to get the effect alignment of the items in either direction, but not for both at the same time.

In detail, I want to align my items by the following rules:

  • The text and picture should align vertically by their upper end.

  • Each item should be at the border of the text area. In my case (see MWE), that would be the text on the left and the picture on the right... at the moment. :)

The most important bit: the solution shall not be based on the picture's measures directly, meaning implementing an offset of 1cm is not of big help in general/for others... I think.

Picture of the Problem, with explanations

enter image description here

MWE for the picture (triangle)

\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}

Actual MWE code

\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}
2
  • 1
    Could you better explain the problem? A tikzpicture behaves like any other character. Your code uses \node around word in first example but not in second, so they don't behave the same.
    – Ignasi
    Mar 31, 2015 at 19:51
  • @Ignasi I changed my op. Happy to edit it again in case it does not suffice!
    – henry
    Apr 2, 2015 at 16:13

2 Answers 2

2

Is this what you are trying to accomplish?

aligned 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}
5
  • This is really close! I edited my op to clarify.
    – henry
    Apr 2, 2015 at 16:13
  • You just need to make the inner sep on the two nodes match, as now shown. Apr 2, 2015 at 17:23
  • Thank you. Some bits I had to change to get it to work: 1. first node has to have right to be inside the text area bounds. 2. the \rule is not right above the two items, but \draw[thick] (WordThingOne.north west) -- (WordThingOne.north -| current page text area.east); is ok.
    – henry
    Apr 2, 2015 at 18:39
  • Oh and beginning a new tikzpicture isn't necessary as far as I reckon.
    – henry
    Apr 2, 2015 at 18:40
  • 1
    That all depends on whether you intend to overlay anything or everything. Apr 2, 2015 at 20:50
1

try this code may be it help

\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}

enter image description here

5
  • 1
    There's no need for parbox, you can use \begin{tikzpicture}[baseline=...] (pgfmanual, p. 123). In this case, \begin{tikzpicture}[baseline=(A)] or \begin{tikzpicture}[baseline=(C)].
    – Ignasi
    Mar 31, 2015 at 20:05
  • @Ignasi thank you may be I will edit my enswer
    – touhami
    Mar 31, 2015 at 20:09
  • Thank you very much for your effort, but as Ignasi has asked, I edited my op to clarify what I actually would like to accomplish.
    – henry
    Apr 2, 2015 at 16:15
  • I am not sure i understand. if you want just adjust some text <Word> with the image. Try this: define a command like this \newlength\mtht \def\adjusttb{% \settoheight{\mtht}{A}% \raisebox{\dimexpr-\height+\mtht\relax}{\includegraphics{picture}}} and than use it: Wellow \hfill \adjusttb
    – touhami
    Apr 2, 2015 at 17:34
  • Thank you, but John's reply sufficed by far. Btw, if you address someone other than the op of a post/reply, you need to add @ in front of the name for a notification.
    – henry
    Apr 3, 2015 at 8:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.