.tex image made with root, text does not scale in latex

Hi All,

I recently learned that with root, you can export tikz files from you canvasses, which is great! Now I’m including it in my latex file and I find that when I make the image smaller or bigger, the text size changes as well. I was actually not expecting this, since I was under the assumption that if you include a tikz image, you can resize it without affecting the text.

What is great, is that the font of all the text in the image is exactly the font that I use for my latex document, so that seems to work. I was wondering if anyone has the same experience, or maybe someone knows if I’m doing something wrong, or if my expectations are wrong :slight_smile:

This is how I include the image in latex:

				\caption{Image ({hpx.tex}) generated thanks to {TTeXDump}}

And I make the plots like this (I do not include all the code here because it is rather big…)

// This is where all the histos are made in the same way
TH1D *allMyHistos(unsigned int metal, unsigned int color, unsigned int nColors, bool clusters, bool strips){
  TH1D *myHist = (TH1D*)allMyFiles->Get("h1");
  // Titles
  myHist->GetXaxis()->SetTitle("Vcth [dac]");
  if(clusters) myHist->GetYaxis()->SetTitle("Clusters/Event");
  else myHist->GetYaxis()->SetTitle("Hits/Event");
  // Axes ranges
  // Line width
  // Colors for the markers and lines
  if(nColors==4) myHist->SetMarkerColor(startColorsFour[metal]+color), myHist->SetLineColor(startColorsFour[metal]+color);
  else if(nColors==10) myHist->SetMarkerColor(startColorsTen[metal]+color), myHist->SetLineColor(startColorsTen[metal]+color);
  else if(nColors==6) myHist->SetMarkerColor(allColors[metal]), myHist->SetLineColor(allColors[metal]);
  // Now return the histogram
  return myHist;
}//end void stripHisto()

// This is where all the cancasses are made in the same way
TCanvas *allMyCanvasses(bool logScale=true){
  TCanvas *myCanvas = new TCanvas();
  // Remove a little bit of white space on the sides
  // Plot in log scale, 
  if(logScale) myCanvas->SetLogy();
  // Return the canvas:
  return myCanvas;
}//end TCanvas allMyCanvasses()

// This is where all the histos are made in the same way
TLegend *allMyLegends(unsigned int size){
  TLegend *myLegend=NULL;
  if(size==6) myLegend = new TLegend(0.14,0.65,0.46,0.94);
  else if(size==4) myLegend = new TLegend(0.14,0.74,0.46,0.94);
  else if(size==10) myLegend = new TLegend(0.14,0.45,0.5,0.94);
  else if(size==41) myLegend = new TLegend(0.14,0.74,0.4,0.94);
  else if(size==61) myLegend = new TLegend(0.14,0.65,0.65,0.94);
  return myLegend;
}//end TLegend allMyLegends()

// This is were the different plot are made
void makeNClustersMetals(unsigned int metal){
  // TCanvas to draw one, and a TLegend to add entries too
  TCanvas *c0 = allMyCanvasses();
  TLegend *l0 = allMyLegends(4);
  // Draw options for in the loop
  unsigned int colorUpdater=0;
  for (unsigned int iSensor=0; iSensor<nSensors; iSensor++){
    for (unsigned int iCbc=0; iCbc<nCbcs; iCbc++) {
      if(fileExists(sensorFileName("clusters", "nClusters", allMeasurements[metal], iSensor, iCbc))){
        allMyFiles = new TFile(sensorFileName("clusters", "nClusters", allMeasurements[metal], iSensor, iCbc), "READ");
        TH1D *plot = allMyHistos(metal, colorUpdater, 4, true, false);
        if(iCbc==0 && iSensor==0) plot->Draw();
        else plot->Draw("same");
        //l0->AddEntry(plot, Form("%s, s%dc%d", allLegends[metal], iSensor, iCbc), "l");
        l0->AddEntry(plot, Form("Sensor %d, CBC %d", iSensor, iCbc), "l");
        cout << MAGENTA << sensorFileName("clusters", "nClusters", allMeasurements[metal], iSensor, iCbc) << " does not exists!" << RESET << endl;
      }//end if fileExists()
    }//end for iCbc
  }//end for iSensor
  c0->SaveAs(totalFileName("rawClusters", allMeasurements[metal]));
  c0->SaveAs(totalFileNamePDF("rawClusters", allMeasurements[metal]));
  // Let's see if we can make a tikz file :)
  gStyle->SetPaperSize(25., 17.6);
  gPad->Print(totalFileNameTIKZ("rawClusters", allMeasurements[metal]));
  delete c0;
}//end void makeNClustersMetals()


_ROOT Version: 6.14/06
_Platform: CentOS 7 (@cern)
_Compiler: g++

I will check but that seems correct …

I tried with:


When I change the value of the scale factor, the size of the picture changes accordingly. The size of text appearing on the picture also change. It is normal as it is part of the picture. I do not see what is wrong with that,

textdump-05.pdf (19.6 KB)
textdump-25.pdf (19.7 KB)

Hi there,
unfortunately I fell for the same trap, that latex-text scales with these tikz-images and have no ‘solution’ to this either. I’m not sure how easy it is to implement but I would really enjoy having a feature with non scaled text, too!
One motivation to have this feature, at least for me, is that you might not know how big the plot has to be and always rerun your script with changed style.

btw: Maybe you’ll find this interesting. This is my try to solve this for me, but I’m struggling there as well: Modify axis of existing TCanvas

What latex text is scaling? The caption ?
I will try to run your example

There’s no text scaling, or better it scales with the scale box in lates, as in your problem.
I thought the idea might be interesting for you.
What I’m trying to accomplish is to write a fuction that saves a canvas with a variety of different axis-sizes, like e.g. ‘small’, ‘medium’ and ‘large’. This would not be ideal, but at least you just have to choose one of the sizes and don’t have to bother with recreation of the plot. But by now my function won’t pick up a new axis-style.

Hi Couet and Hviemann,

Thanks for replying so fast!

So for the text that is scaling I mean the axes labels and the numbers next to the axes. So when I have A4 paper for instance, my image could be 15 cm wide, and I would like to text size to be something like 11pt, also in my graphs. However, let’s say I change the image size, like you did with the scale box, I still want the text of the image to be 11pt for readability, so I don’t want to scale the axes labels.

I thought I could solve this by exporting the TCanvas to a tikz file. Because for instance the font that the canvas has in my latex document is “Times New Roman-like”, while if I look at the .root file it is “Arial-like”. This is what I like, because then I don’t have to worry about the font of my TCanvas any more, if I make it into a tikz file, latex takes care of the font of the TCanvas for me. But this same sort of behaviour is not seem for the font size.


The axis labels are part of the image. If you scale down the picture the axis labels scale down also. If want bigger labels you make them bigger on your initial plot so they will have the right size when you scale down in latex

In bitmaps (png, jpeg), of course it is not possible to include scale-independent elements (text in this case). For tex or vector (ps/eps) figures, I don’t know if it is possible, but I can think of using variables that could be updated (manually, though) when changing the scale. This should be easier in tex files than in postscript :slight_smile:

Here is an example of how the histogram title (``My histo’’) is coded in an exported canvas file (in my case, using root 6.14.06, these lines are by the bottom of the canvas.tex file):
\draw (10,13.0156) node[scale=2.80008, color=c, rotate=0]{My histo};
And a couple of the labels (values of 0 and 200) in the x axis:
\draw [anchor= east] (1.9,2.94906) node[scale=1.01821, color=c, rotate=0]{0};
\draw [anchor= east] (1.9,4.54855) node[scale=1.01821, color=c, rotate=0]{200};

The text sizes are controlled by the scale values (e.g. scale=1.01821), apparently related in some (unknown to me) way to the canvas size. So you could modify the canvas.tex file and replace those numbers by a variable/s that you have to define at the beginning of your main tex file (probably the latex file that will include the figures, not the canvas.tex file/s, but I’m not 100% sure), see here:

For example:
– inside main tex file? –
\def\z{2.80} % for title
\def\x{1.018} % for axis labels
– in canvas.tex –
\draw (10,13.0156) node[scale=\z, color=c, rotate=0]{My histo};
\draw [anchor= east] (1.9,2.94906) node[scale=\x, color=c, rotate=0]{0};
\draw [anchor= east] (1.9,4.54855) node[scale=\x, color=c, rotate=0]{200};
and so on…
Then, to scale the figure inside latex, you only need to change the scale factors at the top of the file.
From one of the replies in the page I mentioned, you should alternatively be able to define the variables inside the tikz (exported canvas) file, using \pgfmathsetmacro{\x}{1.018}, etc.

Hi Couet,

Thanks for the response, I think this is where my confusion is coming from, and I think I should make sure that I have the right “PaperSize” in root. Because at first I thought this was the paper size of my document, however I believe I should tread this more like the size of the image. Then I can choose a text size that works for that image size, which results in a nice image in latex.


Hi @dastudillo,

Thanks, I’ll look into this!


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.