I would like to have a matplotlib plot in my Latex document that uses the same font as the rest of the document. I read in the matplotlib documentation that if you set the rc parameter 'usetex' to true it will use the 'Computer Modern' font, which is also the standard for Latex.
Trying this gave me the following result.
The title of the plot is generated by matplotlib, the caption by the Latex document. As you can see, the font doesn't match. I think both use 'Computer Modern', but not the same font family. The title (by matplotlib) might be something like 'Sans Serif Roman', while the caption (by the Latex document) is something like 'Serif Roman'. I tried to change the font family with the following:
plt.title("Lorem Ipsum", family='serif', fontsize=20)
But it has no effect as long usetex is activated. I also tried it with fontdict, but it also did not change the font in any way. Also writing the name of a font directly to family does not work.
Is there any way to get the same font as in the Latex document?
Ok, after speding yesterday half a day with searching a solution, I now stumbled over it 5 minutes after asking the question.
Solution:
plt.rcParams['font.family'] = 'serif'
For some reason when usetex=True, setting the fontfamily works only globally.
Related
I recently started experimenting with a stylesheet (.mplstyle) for my graphs. I found examples for altering the font globally,specifically for the labels and for titles:
axes.labelweight: bold
axes.titleweight: bold
font.size: 12
However, in the documentation I can't seem to find a way to adjust the ticklabel font, font-size and/or weight. Note that the syntax is different for stylesheets (.mplstyle) than doing it right in the code (for example, using rcParams doesn't seem to work).
I tried the following already but got a "Bad key" error:
Axes.set_yticklabels: fontdict:{'fontsize': 8,
'fontweight': rcParams['axes.titleweight'],
'verticalalignment': 'baseline',
'horizontalalignment': loc}
Very late answer here, but I found your post while trying to figure the same thing out. You've probably figured it out, but I thought I would comment so others that find this post find the answer.
You simply set:
xtick.labelsize : 10
ytick.labelsize : 10
If you want a fontsize of 10 for instance.
I'm trying to see how to embed fonts into my pdf/a.
I found a lot of answer but using iTextSharp.
In my cas I use iText7 and all I tried gave me the error:
"All the fonts must be embedded..."
I have a ttf file for my font but I didn't find a way to embed it into my pdf to use it...
Could someone help me?
Thanks in advance
kor6k
As documented in the tutorial and as indicated by the error you mention ("All the fonts must be embedded"), you need to embed the fonts.
You are probably not defining a font, in which case the standard Type 1 font Helvetica will be used. These standard Type 1 fonts are never embedded, hence you need to pick another font.
The example from the tutorial uses the free font FreeSans:
public const String FONT = "resources/font/FreeSans.ttf";
The font object is defined like this:
PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.WINANSI, true);
This font is used in a Paragraph like this:
Paragraph p = new Paragraph();
p.SetFont(font);
p.Add(new Text("Font is embedded"));
document.Add(p);
This is the C# version. If you need the Java version, take a look at the Java version of the tutorial:
public static final String FONT = "src/main/resources/font/FreeSans.ttf";
PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.WINANSI, true);
Paragraph p = new Paragraph();
p.setFont(font);
p.add(new Text("Font is embedded"));
document.add(p);
If you already use this approach, and you still get the error, you probably have some content somewhere for which you didn't define a font that is embedded.
On a page (TYPO3 Website, ext.: ImageMagick) I want to show thumbnails of available/downloadable pdf-files (always 1st page of the pdf-file as thumbnail). The problem is that the thumbnails (*.gif but I also tried *.jpg and *.png) are created in 'wrong colors', I mean they differ from the pdf content itself (Thumbnails: dark blue color is shown in light blue).
Does anyone has an idea?
This causes PDF with color model CMYK. It will looks fine with ImageMagick when color model is RGB. In such case I prefer to use GraphicsMagick instead of ImageMagick and change the settings in Installtool or LocalConfiguration from for example
$GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'] = 'sRGB';
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] = 'im6';
to
$GLOBALS['TYPO3_CONF_VARS']['GFX']['colorspace'] = 'RGB';
$GLOBALS['TYPO3_CONF_VARS']['GFX']['im_version_5'] = 'gm';
So I am working on generating PDFs using the report4PDF package(bob nemec) from the VisualWorks 8.1 software from Cincom. I am doing everything in 'smalltalk'.
However right now, the issue I am facing is that I can't get a checkbox
character to show up on the PDF.
So my code would go along like this:
pdfDocument := Report4PDF.R4PReport new.
exporter := SAGETEAPDFDataExporter onDocument: pdfDocument.
exporter currentText text string:' Available'.
"Followed by relevant code to save PDF"
But what shows up on my PDF is basically ' Available'. A space appears instead of the checkbox symbol. I even tried using dingbats codes(e.g: #9744 ). Works with the copyright, alpha, gamma symbols. Not with the checkbox symbol.
I tried updating my VisualWorks image from the public repository using the report4pdf, pdf development and fonts development packages. Ran into some
issues which I wont mention since it will derail us from the topic.
Thanks in Advance!
Okay... So I ended up finding a solution to this question. I will just
post the answer here just in case anyone else gets in a similar situation.
pdfDocument := Report4PDF.R4PReport new.
exporter := SAGETEAPDFDataExporter onDocument: pdfDocument.
exporter currentText text:[:text|
text string zapfDingbats ;string:'q'.
text string helvetica; string:'Available' ].
So you can use dingbats font to get a similar character for checkbox. You use
mixed fonts to get something like this:' (Checkbox) Available'.
So that's like the string is: 'q Available'. But 'q' is of the dingbats font while the 'Available' substring is of Helvetica.
Hope that helped. And thank you again #Leandro for trying to help me :)
Cheers!
I am trying to convert this Word document with a header showing an image on the right
http://www.filesnack.com/files/cduiejc7
to PDF using this sample code:
https://github.com/plutext/docx4j/blob/master/src/samples/docx4j/org/docx4j/samples/ConvertOutPDF.java
Here's the result:
http://www.filesnack.com/files/ctjs659h
While the Word document has the header image on the right, the converted PDF shows it on the left.
How can I make docx4j to reproduce the original document as PDF?
Your image is positioned relative to a paragraph:
<w:drawing>
<wp:anchor distT="0" distB="0" distL="114300" distR="114300" simplePos="0" relativeHeight="251658240" behindDoc="0" locked="0" layoutInCell="1" allowOverlap="1" wp14:anchorId="791936E3" wp14:editId="575B92C8">
<wp:simplePos x="0" y="0"/>
<wp:positionH relativeFrom="column">
<wp:posOffset>5317388</wp:posOffset>
</wp:positionH>
<wp:positionV relativeFrom="paragraph">
<wp:posOffset>-325755</wp:posOffset>
</wp:positionV>
docx4j potential to support stuff like that in PDF output is limited by what XSL FO supports. See docx4j's TextBoxTest class for what we can do with text boxes.
Currently, although we can position some textBoxes; we don't do the same for floating images: https://github.com/plutext/docx4j/issues/127
In the meantime, a possible workaround for some cases (eg float right) is to use a table.
Or possibly, you could try putting the image inside a text box!