Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm creating an ER diagram with the TikZ ER library. The manual warns that although key attributes are conventionally underlined, it is hard to implement in TeX and the library uses italics instead. That's fine for me but my teachers probably won't accept the assignment with non-standard notations.

That's why I'm asking the TeX wizard community for a working solution :) Questions that may be relevant are:

MWE from the manual:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{er}

\begin{document}
\begin{tikzpicture}
\node[entity] (sheep) at (0,0) {Sheep}
            child {node [key attribute] {name}};
\node[entity] (genome) at (2,0) {Genome};
\node[relationship] at (1,1.5) {has}
            edge (sheep)
            edge (genome);
\end{tikzpicture}
\end{document}
share|improve this question
1  
I wrote an article on the topic: the er library indeed does not provide automatically a tool to make key attributes underlined. You may want to \underline{attribute} or switch to tikz-er2 which provides a \key command. More information could be found in Drawing relationships between elements of a database. –  Claudio Fiandrino Sep 28 '13 at 13:17
add comment

1 Answer 1

up vote 6 down vote accepted

Assuming I understand the requirements correctly, it is possible to 'capture' the node contents in a box using execute at begin node and execute at end node and do something afterwards with it. This only possible with 'simple' node contents (i.e., basically just text).

\documentclass[border=0.125cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{er}
\newbox\underlinebox
\tikzset{
    key attribute/.append style={
        font=\rmfamily,
        execute at begin node={%
            \setbox\underlinebox=\hbox\bgroup
        },
        execute at end node={%
             \egroup\underline{\box\underlinebox}%
        }
    }
}
\begin{document}
\begin{tikzpicture}
\node[entity] (sheep) at (0,0) {Sheep}
            child {node [key attribute] {name}};
\node[entity] (genome) at (2,0) {Genome};
\node[relationship] at (1,1.5) {has}
            edge (sheep)
            edge (genome);
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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