Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tikz: problem with \centering and node in tikzpicture

1,205 views
Skip to first unread message

Marc van Dongen

unread,
Jul 17, 2009, 6:30:16 AM7/17/09
to
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

unread,
Jul 17, 2009, 7:07:55 AM7/17/09
to
Marc van Dongen schrieb:

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

\path (0,0) node {\tabular{@{}c@{}}a\\a\endtabular};

Herbert

Marc van Dongen

unread,
Jul 17, 2009, 7:13:36 AM7/17/09
to
On Jul 17, 12:07 pm, Herbert Voss <Herbert.V...@fu-berlin.de> wrote:
> \path (0,0) node {\tabular{@{}c@{}}a\\a\endtabular};

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

unread,
Jul 17, 2009, 7:57:25 AM7/17/09
to
Marc van Dongen <don...@cs.ucc.ie> writes:
>On Jul 17, 12:07 pm, Herbert Voss <Herbert.V...@fu-berlin.de> wrote:
>> \path (0,0) node {\tabular{@{}c@{}}a\\a\endtabular};
>
>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

unread,
Jul 17, 2009, 8:14:19 AM7/17/09
to
On Jul 17, 12:57 pm, r...@cl.cam.ac.uk (Robin Fairbairns) wrote:

> (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

unread,
Jul 17, 2009, 8:41:44 AM7/17/09
to
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

Marc van Dongen

unread,
Jul 17, 2009, 10:40:04 AM7/17/09
to
On Jul 17, 1:41 pm, vibrovski <vibrov...@googlemail.com> wrote:

> 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

unread,
Jul 17, 2009, 10:58:44 AM7/17/09
to

>
> 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):
>

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

unread,
Jul 18, 2009, 7:10:46 AM7/18/09
to

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

unread,
Jul 18, 2009, 7:42:36 AM7/18/09
to
On Jul 18, 12:10 pm, Marc van Dongen <don...@cs.ucc.ie> wrote:
> 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

unread,
Jul 18, 2009, 8:52:14 AM7/18/09
to
On Jul 18, 12:42 pm, vibrovski <vibrov...@googlemail.com> wrote:

> 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

unread,
Jul 18, 2009, 5:50:17 PM7/18/09
to
On Jul 18, 1:52 pm, Marc van Dongen <don...@cs.ucc.ie> wrote:
>
> 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

unread,
Jul 19, 2009, 6:32:06 AM7/19/09
to

Nope. This works but the 'text centered' is different from the
'align=center'.

Regards,


Marc van Dongen

vibrovski

unread,
Jul 19, 2009, 3:35:07 PM7/19/09
to
On Jul 19, 11:32 am, Marc van Dongen <don...@cs.ucc.ie> wrote:
>
> 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};

Marc van Dongen

unread,
Jul 20, 2009, 2:42:47 AM7/20/09
to
On Jul 19, 8:35 pm, vibrovski <vibrov...@googlemail.com> wrote:
> On Jul 19, 11:32 am, Marc van Dongen <don...@cs.ucc.ie> wrote:

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

0 new messages