Graphics, Figures & TablesGreek Symbols in Title of Plot

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
eljee
Posts: 4
Joined: Tue May 11, 2010 1:11 pm

Greek Symbols in Title of Plot

Post by eljee »

Hi,

a week or so ago I started using gnuplottex and fell head over heels for it. Now however, we entered a lover's spat.

I'm trying to insert a Greek symbol/letter in my plots but can't seem to get it to work. Is there someone here who has the experience to help me out? I have an example of the code I used below.

Regards,

Eljee


P.S. Not sure whether to mention it or not. I'm using TeX-Live on a Linux Mint 13 system. Using the compiler with a --shell-escape, dvips and ps2pdf to create my files.

Code: Select all

\documentclass{article}
\usepackage{gnuplottex}
\usepackage{graphicx}

\begin{document}
  \begin{figure}[!ht]
    \begin{gnuplot}[scale=0.7, terminal=epslatex]
      set title "My title with a $\pi$ or {/Symbol p} symbol."
      plot sin(x)
    \end{gnuplot}
    \caption{Insert a caption for good measure. Symbols work just fine here $\lambda$.}
  \end{figure}
\end{document}
Last edited by localghost on Tue May 07, 2013 5:23 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Greek Symbols in Title of Plot

Post by Johannes_B »

A quick search led me to the solution:

Code: Select all

\documentclass{article}
\usepackage{gnuplottex}
\usepackage{graphicx}

\begin{document}
  \begin{figure}[!ht]
    \begin{gnuplot}[scale=0.7, terminal=epslatex]
      set title "My title with a $\\pi{}$ or {/Symbol p} symbol."
      plot sin(x)
    \end{gnuplot}
    \caption{Insert a cation for good measure. Symbols work just fine here $\lambda{}$.}
  \end{figure}
\end{document}
The backslash needs to be escaped in Gnuplot.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
User avatar
eljee
Posts: 4
Joined: Tue May 11, 2010 1:11 pm

Re: Greek Symbols in Title of Plot

Post by eljee »

Thanks a lot Johannes,

Of course I did search for a solution online. I must have used the wrong search query. I can imagine that if I ever find another problem with the mixing of either Gnuplot code in LaTeX or the other way around these escapes will work like a charm!
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Greek Symbols in Title of Plot

Post by localghost »

You can evade such problems by using pgfplots instead. The output of the below code sample is attached.

Code: Select all

\documentclass[11pt]{standalone}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\pgfplotsset{
  compat=newest,
  xlabel near ticks,
  ylabel near ticks
}

\begin{document}
  \begin{tikzpicture}
    \begin{axis}[
      title={My title with a $\pi$ symbol},
      tick label style={font=\scriptsize}
    ]
      \addplot[domain=0:2*pi,samples=100] {sin(deg(x))};
      \addlegendentry{Sine curve};
    \end{axis}
  \end{tikzpicture}
\end{document}
The package can use Gnuplot as back-end if necessary. For details please refer to the package manual.


Thorsten
Attachments
wtmp.png
wtmp.png (5.34 KiB) Viewed 11809 times
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

Greek Symbols in Title of Plot

Post by shadgrind »

eljee wrote:I'm trying to insert a Greek symbol/letter in my plots but can't seem to get it to work.
Actually, all you had to do was change the double-quotes to single-quotes when you set the title:

Code: Select all

\documentclass{article}
\usepackage{gnuplottex}
\usepackage{graphicx}

\begin{document}
  \begin{figure}[!ht]
    \begin{gnuplot}[scale=0.7, terminal=epslatex]
      set title 'My title with a $\pi$ symbol.'
      plot sin(x)
    \end{gnuplot}
    \caption{Insert a caption for good measure. Symbols work just fine here $\lambda$.}
  \end{figure}
\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
Post Reply