Discussion:
tikz: problem with \centering and node in tikzpicture
(too old to reply)
Marc van Dongen
2009-07-17 10:30:16 UTC
Permalink
Dear all,


The example below causes an error:

! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
l.7 \path (0,0) node {a\\a
};

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
%\begin{minipage}{1em}
\begin{tikzpicture}
\path (0,0) node {a\\a};
\end{tikzpicture}
%\end{minipage}
\end{document}

If I comment out the \centering, get rid of the linebreak, or un-
comment the minipage environemnt then all goes well.

I take it you cannot use the tikzpicture environment in any context.
If so, is this documented somewhere?

Please note that I'm using pgfCVS2009-06-02_TDS and don't have an easy
way to re-install pgf 2.00.

Thanks in advance.

Regards,


Marc van Dongen
Herbert Voss
2009-07-17 11:07:55 UTC
Permalink
Post by Marc van Dongen
! LaTeX Error: Something's wrong--perhaps a missing \item.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
l.7 \path (0,0) node {a\\a
};
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
%\begin{minipage}{1em}
\begin{tikzpicture}
\path (0,0) node {a\\a};
\path (0,0) node {\tabular{@{}c@{}}a\\a\endtabular};

Herbert
Marc van Dongen
2009-07-17 11:13:36 UTC
Permalink
Thanks Herbert. Of course I could do this:-) but I want to know why
the \centering isn't allowed. Alos, creating the tabular is a bit of
an overhead.

Thanks again.

Regards,


Marc van Dongen
Robin Fairbairns
2009-07-17 11:57:25 UTC
Permalink
Post by Marc van Dongen
Thanks Herbert. Of course I could do this:-) but I want to know why
the \centering isn't allowed. Alos, creating the tabular is a bit of
an overhead.
(speaking as a non-tikz-user) the problem presumably comes from
\centering's redefinition of \\

the \parbox would also restore some standard \\, iirc.
--
Robin Fairbairns, Cambridge
Marc van Dongen
2009-07-17 12:14:19 UTC
Permalink
Post by Robin Fairbairns
(speaking as a non-tikz-user) the problem presumably comes from
\centering's redefinition of \\
the \parbox would also restore some standard \\, iirc.
Thanks! It may also explain why \\ didn't work with \centering.

Regards,


Marc van Dongen
vibrovski
2009-07-17 12:41:44 UTC
Permalink
Hi,

With the latest CVS you can say

\path (0,0) node [align=center] {a\\a};

or something like

\path (0,0) node [text width=0.5cm, text centered] {a\\a};

which is (a bit) cleaner and works with any surrounding \centering

Regards

Mark
Post by Marc van Dongen
Post by Robin Fairbairns
(speaking as a non-tikz-user) the problem presumably comes from
\centering's redefinition of \\
the \parbox would also restore some standard \\, iirc.
Thanks! It may also explain why \\ didn't work with \centering.
Regards,
Marc van Dongen
Marc van Dongen
2009-07-17 14:40:04 UTC
Permalink
Post by vibrovski
With the latest CVS you can say
\path (0,0) node [align=center] {a\\a};
or something like
\path (0,0) node [text width=0.5cm, text centered] {a\\a};
which is (a bit) cleaner and works with any surrounding \centering
Thanks. I was aware of this, but this centers the text at the node
level. I want to cent the whole tikzpicture (inside a figure):

\begin{figure}
\centering
\begin{tikzpicture}
...
\end{tikzpicture}
\end{figure}

Regards,


Marc van Dongen
vibrovski
2009-07-17 14:58:44 UTC
Permalink
Post by Marc van Dongen
Thanks. I was aware of this, but this centers the text at the node
Which is still possible if you the keys in the way I suggested (or
with left alignment or ragged text) as internally they set up the
definition of \\ so that error you were getting does not occur.

Regards

Mark

Mark
Marc van Dongen
2009-07-18 11:10:46 UTC
Permalink
Post by vibrovski
Post by Marc van Dongen
Thanks. I was aware of this, but this centers the text at the node
Which is still possible if you the keys in the way I suggested (or
with left alignment or ragged text) as internally they set up the
definition of \\ so that error you were getting does not occur.
OK. Thanks I misunderstood.

It does work, but I don't think this is a clean solution as you need
to specify the 'text width' attribute, which has to be 'large enough'
but which you don't (want to) know (or think about) in a general
picture. For example, even the change of a font's point size at the
document level may break a hard-coded 'text width'. Having a node with
an actual size (as opposed to the 'text width' size) is clearly
better.

Regards,


Marc van Dongen
vibrovski
2009-07-18 11:42:36 UTC
Permalink
Post by Marc van Dongen
It does work, but I don't think this is a clean solution as you need
to specify the 'text width' attribute, which has to be 'large enough'
but which you don't (want to) know (or think about) in a general
picture. For example, even the change of a font's point size at the
document level may break a hard-coded 'text width'. Having a node with
an actual size (as opposed to the 'text width' size) is clearly
better.
The align key (which uses \halign internally) shown in my original
example allows you to do similar things without specifying the width
of the node.

Regards

Mark

Hope this
Marc van Dongen
2009-07-18 12:52:14 UTC
Permalink
Post by vibrovski
The align key (which uses \halign internally) shown in my original
example allows you to do similar things without specifying the width
of the node.
Thanks, but doesn't for me. The following gives me an error. If I
uncomment the commented line I don't.

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture}
\draw (0,0) node[text centered
%,text width=0.5cm
] {a\\a};
\end{tikzpicture}
\end{document}

Note that without the \centering and without uncommenting the comment,
the tikzpicture isn't centred, which is what I want: I need to have
the tikzpicture centred, regardless of its size.

Regards,


Marc van Dongen
vibrovski
2009-07-18 21:50:17 UTC
Permalink
Post by Marc van Dongen
Thanks, but doesn't for me. The following gives me an error. If I
uncomment the commented line I don't.
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture}
\draw (0,0) node[text centered
%,text width=0.5cm
] {a\\a};
\end{tikzpicture}
\end{document}
So, the following doesn't work for you?

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
\begin{tikzpicture}
\draw (0,0) node[align=center] {a\\a};
\end{tikzpicture}
\end{document}

regards

Mark
Marc van Dongen
2009-07-19 10:32:06 UTC
Permalink
Post by vibrovski
Post by Marc van Dongen
Thanks, but doesn't for me. The following gives me an error. If I
uncomment the commented line I don't.
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
   \begin{tikzpicture}
      \draw (0,0) node[text centered
                      %,text width=0.5cm
                      ] {a\\a};
   \end{tikzpicture}
\end{document}
So, the following doesn't work for you?
\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\centering
   \begin{tikzpicture}
      \draw (0,0) node[align=center] {a\\a};
   \end{tikzpicture}
\end{document}
Nope. This works but the 'text centered' is different from the
'align=center'.

Regards,


Marc van Dongen
vibrovski
2009-07-19 19:35:07 UTC
Permalink
Post by Marc van Dongen
Nope. This works but the 'text centered' is different from the
'align=center'.
Well, perhaps you could provide an example, because to my eyes the
following pairs look identical (CVS pgf version)

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}


\centering
\begin{tikzpicture}
\draw (0,0) node[draw, align=center] {a\\a};
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) node[draw, text width=width("a"),text centered] {a\
\a};
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) node[draw, align=center] {some text\\here};
\end{tikzpicture}

\begin{tikzpicture}
\draw (0,0) node[draw, text width=width("some text"),text
centered] {some text\\here};
\end{tikzpicture}
\end{document}

regards

Mark
Marc van Dongen
2009-07-20 06:42:47 UTC
Permalink
Post by vibrovski
Post by Marc van Dongen
Nope. This works but the 'text centered' is different from the
'align=center'.
Well, perhaps you could provide an example, because to my eyes the
following pairs look identical (CVS pgf version)
[snip]

I think you misunderstood my reply.

In the thread, I gave an example that had 'text centered' in it and I
wrote there was a problem with it. Next, you provided an example with
'align=center' in it and wrote 'So, the following doesn't work for
you?'.

When I replied "This works but the 'text centered' is different from
the 'align=center'" I did not mean that the resulting pictures were
different (I never checked them). Indeed, I wanted to let you know
that *the* 'text centered' was different from *the* 'align=center'. I
wrote this because I didn't get the 'So' in your reply.

Regards,


Marc van Dongen

Loading...