Jupyter cell directive to set custom styles #8008
-
DescriptionIs there a way to achieve this using a cell directive?
Basically, want the equivalent of what can easily do with markdown tables: https://quarto.org/docs/blog/posts/2022-02-15-feature-tables/ But broader nice-to-have would be the ability to set a custom class AND define its style in the same cell. Is that possible? Something like
related: #3964 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
How are you producing your table withing computation cell ? If you are generating HTML table, the style you set should be set. If you are generating Markdown table, you should use tool that knows how to produce pipe tables Example: ```{python}
#| label: tbl-planet-measures
#| tbl-cap: Astronomical object
from IPython.display import Markdown
from tabulate import tabulate
table = [["Sun","696,000",1.989e30],
["Earth","6,371",5.972e24],
["Moon","1,737",7.34e22],
["Mars","3,390",6.39e23]]
Markdown(tabulate(
table,
headers=["Astronomical object","R (km)", "mass (kg)"],
colalign = ("left", "right", "right")
))
``` If you want to set some HTML style on tables using CSS, you can use the CSS selector that match the id you set on the table Quarto does not generate the table, so it is quite hard to do something a YAML option that contains style to apply on a HTML table element.
|
Beta Was this translation helpful? Give feedback.
-
The table is Pandas dataframe displayed in the cell. Basically, the first cell here. |
Beta Was this translation helpful? Give feedback.
-
Thanks a lot for your response. I think the directive I was after is Would would it take to make the below possible?
|
Beta Was this translation helpful? Give feedback.
This is a matter of CSS and HTML element.
About this,
#| class-output: { text-align: right; }
, this is really a mix of several things.{ text-align: right; }
is CSS, it needs to be applied to a selector or something.class-output
in knitr ecosystem is for setting aclass
onto the output div, no matter what is inside.Quarto equivalent of
class-output
would be#| classes:
, which will apply a class to the output div. Example:This means that your table will be somewhere below a
div.my-table
and you can then easily target using CSS in your theme file.This is wha…