1

Here are my files reduces for the MWE :

file 1 :

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
   
\begin{document}

\input{Chaine_Fonctionnelle}

\end{document}

file 2 :

\documentclass[border=2pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}


\begin{document}

\input{Chaine_Fonctionnelle}
 
\end{document}

Chaine_Fonctionnelle.tex :

% \tikzset{font=\fontsize{12pt}{14pt}\selectfont}
\begin{tikzpicture}[scale=.8]
        \node[line width=2pt, minimum width=5cm, text width=3.8cm,minimum height=5cm, rectangle] (Ali) at (0,0) {};
        \draw[line width=2pt] (Ali.east)--(Ali.west);
        \node[font=\large\bfseries, anchor=south, above = 1cm,align=center,inner sep=-18pt] at (Ali.south) {Redresseur  \\ (pont de diodes)\\ + filtre \\ (Condensateur)};
\end{tikzpicture}
    

here is the version from the article : ArticleVersion

here is the version from the standalone : enter image description here

I've tried a few things that showed me what causes the differences. For example I can remove the 12 points from the first line of the article, then the two images look the same, but I would like a solution that doesn't imply a change at this top line.

I've tried local changes like the commented line, but to no avail.

I thought the hierarchy was putting local indication above global indication, but I can't seem to overrule that 12 point from the documentclass command.

Can you help me ?

First Edition ---------------- :

Thank you for your answers and comments, I'll try make a few changes try and avoid some problems : avoiding negative value for inner sep, for that I'll anchor the text to the middle of the line, but the problem doesn't go away :

New file Chaine_Fonctionnelle.tex :

% \tikzset{font=\fontsize{12pt}{14pt}\selectfont}
\begin{tikzpicture}
        \node[draw,line width=2pt, minimum width=5cm, minimum height=4.2cm, rectangle] (Ali) at (0,0) {};
        \draw[line width=2pt] (Ali.east)--(Ali.west) node[midway] (MidAli) {};
        \node[font=\large\bfseries, anchor=north, align=center] at (MidAli) {Redresseur  \\ (pont de diodes)\\ + filtre \\ (Condensateur)};
\end{tikzpicture}

Here are the result, first from the standalone then from the article compilation : NewStandalone NewArticle

You can see the two compilations still give different results.

8
  • 2
    you have specified a fixed amount of over print inner sep=-18pt that is always liable to cause the text to overprint the surrounding material depending on the spacing where it is included. Commented Jun 13 at 19:58
  • @david-carlisle Thanks you for your comment, I have edited my question to provide a version without the negative inner sep , but there is still a difference between the standalone compilation and the article one.
    – LMT-PhD
    Commented Jun 16 at 18:30
  • 1
    well you are using article at 12pt and standalone at 10pt so naturally you have different size fonts Commented Jun 16 at 18:52
  • @david-carlisle , I would like to add a parameter to my tikzpicture included in both document so that it does not depend on the document general font size.
    – LMT-PhD
    Commented Jun 16 at 19:16
  • 2
    why? everything about the text in the tikz depends on the document settings, the font the text style, baseline spacing, not just the font size. Commented Jun 16 at 19:18

1 Answer 1

1

Try using the following instead. This code uses the positioning library and places the node below the centre of the reference node, rather than above its bottom. It dispenses with the inner sep specification.

Note that scale=0.8 is doing nothing whatsoever. Try scale=0.1 and notice that the standalone image has precisely the same dimensions.

\begin{filecontents}[overwrite]{\jobname-1.tex}
\begin{tikzpicture}%[scale=.8] this has no effect
  \node[line width=2pt, minimum width=5cm, text width=3.8cm,minimum height=5cm, rectangle] (Ali) at (0,0) {};
  \draw[line width=2pt] (Ali.east)--(Ali.west);
  \node[font=\large\bfseries, anchor=north, below =.25cm of Ali.center,align=center]  {Redresseur\\(pont de diodes)\\+ filtre\\(Condensateur)};
\end{tikzpicture}
\end{filecontents}
\documentclass[a4paper,12pt]{article}
% \documentclass[border=2pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\input{\jobname-1}
\end{document}

EDIT

From my comment at the request of the OP.

One of the main advantages of using tikz/pgf or similar is that it ensures the fonts and spacing in your diagrams are consistent with those in the document.

There is no practical way to make such diagrams independent of the surrounding environment. To do that you'd have to essentially do class and package setup inside the tikzpicture. But a major reason to use \input (and TikZ) is to ensure the picture is sensitive to the context e.g. that the fonts are consistent with those used in the document, that the size of skips and font-dependent dimensions such as em and ex match etc.

If that's not what you want, compile your images separately and use \includegraphics. If you don't want the context-sensitivity, there's no disadvantage to \includegraphics. That's often the right choice for things like logos, but generally sub-optimal for things like diagrams.

8
  • Thank you for answering. scale does not visibly change this MWE but it does change the whole figure, some features are impacted by scale and not others. I use positioning to put the text in the bottom half part of a rectangle (that is cut in half by the line), and I use the inner sep to adjust the vertical position when the text has several lines instead of one. Using the center of the rectangle instead of the bottom as reference point would just move the problem. I'm looking for a solution that would give the same result for the tikzpicture in the standalone and in the article.
    – LMT-PhD
    Commented Jun 15 at 19:16
  • 1
    @LMT-PhD It doesn't just move the problem. It illustrates a more fruitful strategy for positioning. Making inner sep negative is inviting trouble. You are much more likely to get consistent results with a strategy which doesn't rely on that kind of manipulation. Very occasionally, that kind of adjustment is useful to create a special effect (overlapping) or to provide a quick fix for a problem you don't have the time and/or inclination to fix properly. But it will have all kinds of side-effects e.g. it may mess up the bounding box.
    – cfr
    Commented Jun 15 at 19:43
  • 1
    @LMT-PhD scale doesn't change this example, so it isn't necessary in your minimised code. I didn't mean to suggest it doesn't make any difference to anything. But you don't need it here. If my particular suggestion doesn't work, there are other sane strategies e.g. use a split node or (possibly overkill) a matrix or two nodes or whatever. The point is to avoid having to fudge things with the kind of adjustments that cause trouble. See also tex.stackexchange.com/questions/720516/….
    – cfr
    Commented Jun 15 at 19:50
  • 1
    @LMT-PhD Are you asking how to standardise the font size? Add 12pt to the options for standalone if you want the same size fonts in both pictures.
    – cfr
    Commented Jun 16 at 18:47
  • 1
    Thank you cfr I've discussed with david-carlisle and it seems there are no way to meet all my requirements. So if you conclude as well that there is no way of making the font in the input independent from the document around, could you sum it up in a conclusion to your answer including your last comment remarks so that I can mark it as solved ? Thank you for your help
    – LMT-PhD
    Commented Jun 19 at 6:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .