2

I have a pgfplots graphic in a pgfplotstable, and a part of the graphic is overlapped by the table like you can see in this picture: Problem illustration

The 800 at the top is cut by the tabular border.

Here is a MWE:

\documentclass[border=10pt]{standalone}
\usepackage{filecontents}
\begin{filecontents}{data.txt}
n   T1  T2  MCp Q1  Q2  T
1   295 145 8   0   1200    95
2   145 45  2   100 100 95
3   195 45  3   150 300 95
4   195 295 5   0   500 95
5   95  195 8   0   800 95
6   45  195 4   200 400 95
\end{filecontents}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
% Read data file
\pgfplotstableread{data.txt}\data

\begin{document}
\newcommand\powernode[4]{%\powernode{T°}{nL1}{NL2}{Q}
\addplot+[black,solid] coordinates {(#1,#2+0.4) (#1,#3-0.4)};
\node[draw, circle] at (axis cs:#1,#2) { };
\node[draw, circle] at (axis cs:#1,#3) { };
\node at (axis cs:#1,#2-0.5) {\tiny #4};
}

\pgfplotsset{every axis plot post/.append style={mark=arrow}}

% Get number of rows in datafile
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval

% Print the table
\pgfplotstabletypeset[columns={n,T,MCp,Q1,Q2},
  % Booktabs rules
  every head row/.style = {before row=\toprule, after row=\midrule},
  every last row/.style = {after row=[3ex]\bottomrule},
  % Set header name
  columns/n/.style = {string type, column name=Flux},
  % Call the command in a multirow cell in the first row, keep empty for all other rows
  columns/T/.style = {
    column name = {},
    assign cell content/.code = {% use \multirow for Z column:
    \ifnum\pgfplotstablerow=0
    \pgfkeyssetvalue{/pgfplots/table/@cell content}
    {\multirow{\numberofrows}{7cm}{
    \begin{tikzpicture}[trim axis left,trim axis right]
        \begin{axis}[y=-\baselineskip,
            scale only axis,
            width             = 6.5cm,
            enlarge y limits  = {abs=0.5},
            axis y line*      = middle,
            y axis line style = dashed,
            ytick             = \empty,
            axis x line*      = bottom]
          \addplot+[red,->,solid] coordinates {(295,1) (145,1)};
          \addplot+[red,->,solid] coordinates {(145,2) (45,2)};
          \addplot+[red,->,solid] coordinates {(195,3) (45,3)};
          \addplot+[blue,->,solid] coordinates {(195,4) (295,4)};
          \addplot+[blue,->,solid] coordinates {(95,5) (195,5)};
          \addplot+[blue,->,solid] coordinates {(45,6) (195,6)};
          \addplot+[black,solid,thick] coordinates {(95,1) (95,6)};
          \powernode{125}{2}{6}{100}
          \powernode{175}{3}{6}{300}
          \powernode{160}{1}{5}{800}
        \end{axis}
    \end{tikzpicture}
    }}%
    \else
    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
    \fi
    }
  },
  % Format numbers and titles
  columns/MCp/.style = {column name = MCP, fixed, dec sep align, use comma, set thousands separator={\ }},
  columns/Q1/.style  = {column name = $Q_1$, fixed, dec sep align, use comma, set thousands separator={\ }},
  columns/Q2/.style  = {column name = $Q_2$, fixed, dec sep align, use comma, set thousands separator={\ }}
]{\data}
\end{document}

Is it possible to make the tabular border background transparent so the 800 would be displayed correctly?

I know my MWE is not really minimal. I posted that much because I'll be sure the problem is solved if solved on this example, and that I know that my way to manage my code is not the optimal way, so that allow for suggestion on this side too. And even if this is not optimal, it may inspire other that would be interested on similar result. I'm aware that the physics behind the problem is not respected, it's an example for the drawing point of view

2
  • Running the tikzpicture by itself causes the 800 to get clipped. Expand y limits = {abs=.7} will fix that. Nov 20 '14 at 22:16
  • @JohnKormylo venlarge y limits = {abs=0.7}, does in deed fully display the 800, but it modify the size of the graphic in a way that the red and blues lines are no more perfectly aligned with the tabular.
    – Togh
    Nov 21 '14 at 8:38
2

Running the tikzpicture by itself causes the 800 to get clipped. Expanding the y limits via enlarge y limits = {abs=0.7}, will fix that.

Additionally you can use \raisebox to adjust the alignment. Note, the first argument of \raisebox moves the baseline, which has no effect. The second argument changes the (apparent) height. The 3.05cm was obtained by trial and error.

plottable

\documentclass[border=10pt]{standalone}
\usepackage{filecontents}
\begin{filecontents}{data.txt}
n   T1  T2  MCp Q1  Q2  T
1   295 145 8   0   1200    95
2   145 45  2   100 100 95
3   195 45  3   150 300 95
4   195 295 5   0   500 95
5   95  195 8   0   800 95
6   45  195 4   200 400 95
\end{filecontents}
\usepackage{pgfplots}
\pgfplotsset{compat=1.10}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{multirow}
% Read data file
\pgfplotstableread{data.txt}\data

\begin{document}
\newcommand\powernode[4]{%\powernode{T°}{nL1}{NL2}{Q}
\addplot+[black,solid] coordinates {(#1,#2+0.4) (#1,#3-0.4)};
\node[draw, circle] at (axis cs:#1,#2) { };
\node[draw, circle] at (axis cs:#1,#3) { };
\node at (axis cs:#1,#2-0.5) {\tiny #4};
}

\pgfplotsset{every axis plot post/.append style={mark=arrow}}

% Get number of rows in datafile
\pgfplotstablegetrowsof{\data}
\let\numberofrows=\pgfplotsretval

% Print the table
\pgfplotstabletypeset[columns={n,T,MCp,Q1,Q2},
  % Booktabs rules
  every head row/.style = {before row=\toprule, after row=\midrule},
  every last row/.style = {after row=[3ex]\bottomrule},
  % Set header name
  columns/n/.style = {string type, column name=Flux},
  % Call the command in a multirow cell in the first row, keep empty for all other rows
  columns/T/.style = {
    column name = {},
    assign cell content/.code = {% use \multirow for Z column:
    \ifnum\pgfplotstablerow=0
    \pgfkeyssetvalue{/pgfplots/table/@cell content}
    {\multirow{\numberofrows}{7cm}{\raisebox{0pt}[3.05cm]{%
    \begin{tikzpicture}[trim axis left,trim axis right]
        \begin{axis}[y=-\baselineskip,
            scale only axis,
            width             = 6.5cm,
            enlarge y limits  = {abs=0.7},
            axis y line*      = middle,
            y axis line style = dashed,
            ytick             = \empty,
            axis x line*      = bottom]
          \addplot+[red,->,solid] coordinates {(295,1) (145,1)};
          \addplot+[red,->,solid] coordinates {(145,2) (45,2)};
          \addplot+[red,->,solid] coordinates {(195,3) (45,3)};
          \addplot+[blue,->,solid] coordinates {(195,4) (295,4)};
          \addplot+[blue,->,solid] coordinates {(95,5) (195,5)};
          \addplot+[blue,->,solid] coordinates {(45,6) (195,6)};
          \addplot+[black,solid,thick] coordinates {(95,1) (95,6)};
          \powernode{125}{2}{6}{100}
          \powernode{175}{3}{6}{300}
          \powernode{160}{1}{5}{800}
        \end{axis}
    \end{tikzpicture}
    }}}%
    \else
    \pgfkeyssetvalue{/pgfplots/table/@cell content}{}%
    \fi
    }
  },
  % Format numbers and titles
  columns/MCp/.style = {column name = MCP, fixed, dec sep align, use comma, set thousands separator={\ }},
  columns/Q1/.style  = {column name = $Q_1$, fixed, dec sep align, use comma, set thousands separator={\ }},
  columns/Q2/.style  = {column name = $Q_2$, fixed, dec sep align, use comma, set thousands separator={\ }}
]{\data}
\end{document}

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.