2

I have the problem that whenever I set the preamble right so that I can use the characters æ ø å in the text of the document with no problem, the special characters in tables that are entered look weird. Like in the following example:

\documentclass[12pt,a4paper]{article}  
\usepackage[T1]{fontenc}  
\usepackage[english, norsk]{babel}  
%\usepackage[utf8]{inputenc}  

\begin{document}  

\section{Introduction}

æ

ø

å

\begin{table}
\caption[c]{æ ø å}
\begin{tabular}{l r r r r r r r r }
\hline
\input{testtable.tex}
\end{tabular}
\end{table}

\end{document}

The table looks like this:

\hline  
åÅå   &       0.875&        3192 \\  
æÆæ &      0.0793&        3192 \\   
øØø &       30.61&        1671 \\  
\hline

Including

\usepackage[utf8]{inputenc}

in the preamble makes the characters in the table look fine, but then texworks can't compile due to the special characters used in the text of the article. Anyone understand why?

Thanks! Sara

Edit:

Output 1

The image above is what my output looks like when I do not include the
% !TeX encoding = utf8
suggested by @Sveinung.

Output 2

The image above shows how it looks when I do include that line: Now also the characters in the text are wrong.

My settings look like this:

enter image description here

I have encoded both the main file and the input file to UTF-8 using Notepad.

  • 2
    Are you sure the document is actually being saved as UTF8? – daleif Nov 5 '19 at 12:46
  • 3
    What are the contents of TABLEWITHÆØÅ.tex? Can you save that file using only ascii in the filename? The filename is a different problem than getting the characters to appear in the output document. Both problems are unrelated to using a table. – Teepeemm Nov 5 '19 at 12:47
  • @daleif: How can I see if the document is being saved as UTF8? – user200771 Nov 5 '19 at 13:06
  • 2
    Your files seems to have different encodings: the main file is 8bit, the table utf8. You should ensure that every file has the same encoding - utf8 is today the standard. Try to create a new main file in utf8 and then copy and paste the content of your current main file in it, and then use the utf8 option. – Ulrike Fischer Nov 5 '19 at 13:22
  • 1
    See Get encoding of a file in Windows how to check the encoding of text files under Windows. Under Linux/Unix/... use the command file on the command line; file myfile.tex will tell you the encoding. – gernot Nov 5 '19 at 14:16
1

First check that Texworks is set up to use UTF8. Click the Edit-menu, choose Preference, and you get a window that shall look like the screenshot below regarding character set.

enter image description here

Then add to both files:

% !TeX encoding = utf8 

Then ensure that both file actually are saved as UTF8-files. Texworks does not convert an ANSI-file to UTF8 on saving, even if you have set up the UTF8 option. Therefore, you have to copy the file content and paste it into a brand new file, and save it again as UTF8. Or you can runt the file through a stand alone filter.

For unknown reasons, the file did not compile as long \hline was the first commands in the testtable.tex. Therefore, I moved that line to the main file.

enter image description here

MWE:

% !TeX encoding = utf8  %% Add this string
\documentclass[12pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[english, norsk]{babel}
%\usepackage[utf8]{inputenc}

\begin{document}

\section{Introduction}

æ

ø

å

\begin{table}
\caption[c]{æ ø å}
\begin{tabular}{l r r}
\hline
\input{testtable.tex}
\end{tabular}
\end{table}

\end{document}


% testtable.tex
% !TeX encoding = utf8  %% Add this string
%\hline
åÅå & 0.875& 3192 \\
æÆæ & 0.0793& 3192 \\
øØø & 30.61& 1671 \\
%\hline
| improve this answer | |
  • Thanks, but that did not work either -- still the same issue. – user200771 Nov 5 '19 at 13:38
  • I copied your code exactly, still my output has the æøå in the table looking all wrong. Could the issue be with texworks? – user200771 Nov 5 '19 at 14:49
  • @user200771 Why don't you take a screenshot and add the picture to your question so people can understand exactly what you mean by "all wrong" – Au101 Nov 5 '19 at 14:57

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.